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

Skipping with continue

Skip the rest of one iteration and move to the next.

Go code

for i := 1; i <= 3; i++ {
    if i == 2 {
        continue
    }
    fmt.Println(i)
}
Line-by-line explanation
  1. The loop visits 1, 2, and 3.
  2. At 2, continue skips the remaining body.
  3. Println runs for 1 and 3.
Expected output
1
3

This is the expected result.