Go Keyword range: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
* [[Go for#for_Controlled_by_a_.22range.22_Clause|for]] | * [[Go for#for_Controlled_by_a_.22range.22_Clause|for]] | ||
< | =Overview= | ||
<tt>range</tt> keyword is used to iterate over arrays, slices and maps. It returns two value, on the first position is the index/kyes, and the second position is the value. | |||
</ | <pre> | ||
var a [5]int | |||
for i, value := range a { | |||
// i is the index | |||
// value is the value | |||
} | |||
</pre> |