0Pricing
Swift Academy · Lesson

break and continue Basics

Exit or skip iterations cleanly.

What break Does

The break statement immediately exits the innermost loop, skipping any remaining iterations.

for n in 1...10 {
    if n == 4 {
        break
    }
    print(n)
}
print("done")

What continue Does

The continue statement skips the rest of the current iteration and jumps to the next one.

for n in 1...6 {
    if n % 2 == 0 {
        continue
    }
    print(n)
}

All lessons in this course

  1. break and continue Basics
  2. Labeled Statements
  3. Breaking Out of Nested Loops
  4. Loop Control in switch Context
← Back to Swift Academy