4 ms·
I think you need to provide an example of what you're trying to say, as the syntax you showed above is not valid. the := operator is for defining a new variabl
by kyrra 12y ago
I think you need to provide an example of what you're trying to say, as the syntax you showed above is not valid. the := operator is for defining a new variable, not for creating a new instance of some type. The := operator is just shorthand.
foo := 5
is shorthand for:
var foo int
foo = 5
the "range" keyword over an array gives you the index and the value at that index. If you don't need the index or the value, you can put a "_" in it's place (to save on the allocation).
http://play.golang.org/p/Z2ejUlN5An http://play.golang.org/p/Z2ejUlN5An
You'll notice that foo[i] is still printing "0", because range always creates a copy of the object assigned into v. Unless you start using pointers, you'll never have mutation issues.