Range
For slice or map
The range
form of the for
loop iterates over a slice or map.
When ranging over a slice, two values are returned for each iteration. The first is the index, and the second is a copy of the element at that index.
Example
Skip or Omit
The index or value can be skipped by assigning to _
.
If you only want the index, you can omit the second variable.
Example
Last updated