Go Keyword range: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 6: Line 6:
=Overview=
=Overview=


<tt>range</tt> keyword is used to iterate over arrays, slices, maps and [[Go Concepts - Functions#Variadic_Arguments|variadic function arguments]]. It returns two value, 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#Variadic_Functions|variadic function arguments]]. It returns two value, on the first position is the index/kyes, and the second position is the value.


<pre>
<pre>

Revision as of 03:59, 28 March 2016

Internal

Overview

range keyword is used to iterate over arrays, slices, maps and variadic function arguments. 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
}