golang for loop array range code example
Example 1: loop list golang
a := []string{"Foo", "Bar"}
for i, s := range a {
fmt.Println(i, s)
}
Example 2: go iterate over slice
nums := []int{2, 3, 4}
sum := 0
for _, num := range nums {
sum += num
}
fmt.Println("sum:", sum)