Go—Range (Basics)

Go has an almost Python-like function: Range.
Range is used to iterating over elements in a lot of different Go data structures.

Of course, we can range over slices and arrays, like:

We get both the value and index when using the range function, though in the above example we didn’t use it.

But we can also use range to go over the items on a map, getting both the key and value of each item on the map:

Another use of the range is to range over the Unicode points of a string in go:

--

--

Nikolaj Johannes Skole Jensen

Fullstack developer living in Denmark. Experience with both Web- and App development.