Iterations over slices, maps, channels are very cool, usually straight to the point :
func main() {
for _, a := range []int{6, 4} {
for _, b := range []int{2, 3} {
for fname, f := range map[string]func(int, int) int{
"plus": func(x, y int) int { return x + y },
"minus": func(x, y int) int { return x - y },
"times": func(x, y int) int { return x * y },
"div": func(x, y int) int { return x / y },
} {
fmt.Println(a, fname, b, "is", f(a, b))
}
}
}
}
PlaygroundThen you may tell some specific details : why the underscores for ignored iteration variables, and why the map iteration order is not the same as the order in the code. Also, I find these iterations quite versatile in practice, but they work only on built-in types (you won't have java-like custom iterables).
Cheers
Val