for Is the Only Loop
for has three parts, a while form and an infinite form. range walks collections.
Example
package main
import "fmt"
func main() {
for i := 0; i < 3; i++ {
fmt.Print(i, " ")
}
n := 3
for n > 0 {
fmt.Print(n, " ")
n--
}
fmt.Println()
}Result
0 1 2 3 2 1
Exercise
While style loop.
for > 0 {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.