Loops in Go
From the Go cheat sheet Β· Control Flow Β· verified Jul 2026
Loops
For loops and iterations
go
// Basic for loop
for i := 0; i < 10; i++ {
fmt.Println(i)
}
// While-style loop
for x < 100 {
x *= 2
}
// Range over slice
for i, v := range slice {
fmt.Printf("%d: %v\n", i, v)
}π Only for loops (no while/do-while)
π range for iterating collections
π·οΈ Labels for breaking nested loops
β‘ range on channels until closed