Go Keyword range: Difference between revisions

From NovaOrdis Knowledge Base
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]]


<font color=red>
=Overview=
Used for:
 
* iterating over slices
<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.
* iterating over maps
 
</font>
<pre>
var a [5]int
for i, value := range a {
  // i is the index
  // value is the value
}
</pre>

Revision as of 22:50, 27 March 2016

Internal

Overview

range 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.

var a [5]int
for i, value := range a {
   // i is the index
   // value is the value
}