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

Why Go Has One Loop

Understand repetition and why Go uses only the for keyword.

Other languages use several loop keywords. Go keeps one keyword, for, and changes its shape for counting, condition-based, and endless loops.

Go code

for {
    fmt.Println("Once")
    break
}
Line-by-line explanation
  1. For with no condition begins an endless loop.
  2. Println displays Once.
  3. Break immediately ends the loop.
Expected output
Once

This is the expected result.