Go · Stage 4 – Repeating Things · Lesson 26 of 64

for as a while Loop

Repeat while one condition stays true.

Go code

count := 1
for count <= 3 {
    fmt.Println(count)
    count++
}
Line-by-line explanation
  1. Count starts at 1.
  2. For checks one condition.
  3. The current count is displayed.
  4. Count increases so the loop can stop.
Expected output
1
2
3

This is the expected result.