for ... range
Iterates over a slice/map/string.
Syntax
for i, e := range slice { }Description
range provides the index (or key in a map) along with each element. Use _ if the index is not needed.
Example
Loading editor…
Expected output
red purple
When to use?
Iterating over lists/maps.