golang foreach code example
Example 1: loop list golang
a := []string{"Foo", "Bar"}
for i, s := range a {
fmt.Println(i, s)
}
Example 2: foreach golang
package main
import "fmt"
func main() {
myList := []string{"dog", "cat", "hedgehog"}
// for {key}, {value} := range {list}
for _, animal := range myList {
fmt.Println("My animal is:", animal)
}
}