Go has a helpful range keyword that works similar to enumerate in python. Ranging over a slice produces indexes and elements and ranging over a map produces key value pairs.
Range over slice/map
slice := []string{"hello", "world", "!"}
for i, element := range slice {
fmt.Println(i, element, ":")
for _, ch := range element {
fmt.Printf(" %q\n", ch)
// %q prints out a rune an not an unsinged int
}
}Range over int
Go also lets you shortcut the full for loop syntax by ranging over an integer.
for i := range 10 {
// i will go from 0 to 9 and then the loop will exit
}