0Pricing
Swift Academy · Lesson

Labeled Statements

Target outer loops with named labels.

What Is a Label

A statement label names a loop so you can target it precisely with break or continue.

outer: for i in 1...3 {
    print("row", i)
}

Label Syntax

Write the label name followed by a colon directly before the loop keyword.

search: for n in 1...5 {
    print(n)
    if n == 3 { break search }
}

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