Quantcast
Channel: Golang mixed assignment and declaration - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by user for Golang mixed assignment and declaration

In short: as a, b = 2, 3 means "assign both" and a, b := 2, 3 means "declare and assign both", and you need to assign one and declare and assign the other, the solution is to declare the other and...

View Article



Answer by user6169399 for Golang mixed assignment and declaration

your Question has 2 parts:first part:= is just assignment:= is define and assign for new vars(at least one new var) inside the function block(not global), working sample:package mainimport ("fmt")func...

View Article

Answer by user539810 for Golang mixed assignment and declaration

What you're experiencing is commonly known as "variable shadowing". When you use := with any variable in an inner scope, including in statements like if and for despite the lack of braces, a new value...

View Article

Answer by jnmoal for Golang mixed assignment and declaration

According to thegolang the documentation:An identifier declared in a block may be redeclared in an inner block.That's exactly what your example is showing, a is redeclared within the brackets, because...

View Article

Golang mixed assignment and declaration

I started working with go for a few weeks, and (once again) I stumbled across something that seems odd for me:// Not workinga := 1{ a, b := 2, 3}// Worksa := 1a, b := 2, 3playgroundI want to assign two...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>