Module 02 Β· Collections β Lesson 3 of 3 Β· ~11 min
Ranging & strings
One loop keyword to walk anything
Go has exactly one loop keyword β for β and its range form walks slices, maps, and strings. Over a slice, range gives you two things each turn: the index and a copy of the value.
fmt.Println(i, name) }
Over a map, range gives the key and the value instead (order random, as you saw):
fmt.Println(id, rating) }