Range

The expression on the right in the range clause is called a range expression, which can be an array, a pointer to an array, a slice, a string, a map or a channel that allows receive operations.

As with an assignment, if present, the left operands must be addressable or map index expressions; they denote the iteration variables.

If the range expression is a channel, at most one iteration variable is allowed, otherwise there can be up to two.

If the last iteration variable is the blank identifier, the range clause is equivalent to the same clause without that identifier.


Expression range                       1° value       2° value

array or slice a [n]E, *[n]E, or []E  index   i int  a[i]         E
string         s string type          index   i int  see below  rune
map            m map[K]V              key     k K    m[k]         V
channel        c chan E, <-chan E     element e E
                        
range.go