Go Keyword range: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 8: | Line 8: | ||
<tt>range</tt> keyword is used to iterate over arrays, slices, maps and [[Go_Concepts_-_Functions#Varidic_Functions|variadic function arguments]]. It returns two values. On the first position is the index/kyes, and the second position is the value. | <tt>range</tt> keyword is used to iterate over arrays, slices, maps and [[Go_Concepts_-_Functions#Varidic_Functions|variadic function arguments]]. It returns two values. On the first position is the index/kyes, and the second position is the value. | ||
<blockquote style="background-color: Gold; border: solid thin Goldenrod;"> | |||
:Note that only a first identifier is declared, that is the ''index'' and not the value, as the intuition would suggest. See examples below:<br> | |||
</blockquote> | |||
<pre> | <pre> |
Revision as of 04:27, 28 March 2016
Internal
Overview
range keyword is used to iterate over arrays, slices, maps and variadic function arguments. It returns two values. On the first position is the index/kyes, and the second position is the value.
- Note that only a first identifier is declared, that is the index and not the value, as the intuition would suggest. See examples below:
var a [5]int for i, value := range a { // i is the index // value is the value }