https://golang.org/ref/spec#For_range
For statements with range clause
For an array, pointer to array, or slice value a, the index iteration values are produced in increasing order, starting at element index 0. If at most one iteration variable is present, the range loop produces iteration values from 0 up to len(a)-1 and does not index into the array or slice itself. For a nil slice, the number of iterations is 0.
According to the spec, iterating over a linear data structure (array or slice or string) in Go will get each of elements in there always in order the index increases.
for i, v := range []int{11, 22, 33, 44} {
fmt.Println(i, v)
}
But the thing is that I can't really find in the spec the guarantee that,
this range-iterate-over clause with an implicit index iteration value, too, will always keep the same order as well:
for _, v := range []int{11, 22, 33, 44} {
fmt.Println(v)
}
Will those two examples I put above always perform in the same order?
I assume they do but I haven't heard the promise yet.
How does for ... range
work when the index iteration value is represented by the blank identifier(the underscore _
)?