DEV Community

Discussion on: For Loop in different programming languages

Collapse
 
antjanus profile image
Ant The Developer

Here's one for Go:

myStr := "My string"

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

You can also use a while loop:

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

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