DEV Community

Discussion on: For Loop in different programming languages

Collapse
 
antjanus profile image
Antonin J. (they/them)

Here's one for Go:

myStr := "My string"

for i := 0; i < len(myStr); i++ {
  fmt.Printf("%c", myStr[i])
}

You can also use a while loop:

for _, char := range myStr {
  fmt.Printf("%c", char)
} 

Note how a "while loop" is basically the same as a for loop.