While Loops
x := 0for x < 10 { fmt.Println(x) x++}
Consequently there is also no do while
loop in Go, again you can achieve the same functionality using for
loops:
x := 0for { fmt.Println(x) x++ if x >= 10 { break }}
Infinite Loops
Section titled “Infinite Loops”You can create an infinite loop in Go using the for
statement without any condition:
for { fmt.Println("This will run forever!")}