for each golang string code example
Example 1: loop list golang
a := []string{"Foo", "Bar"}
for i, s := range a {
fmt.Println(i, s)
}
Example 2: iterating through string golang
package main
import (
"fmt"
"strings"
)
func main() {
words := strings.Fields("This, that, and the other.")
for i, word := range words {
fmt.Println(i, " => ", word)
}
}