100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Swift

Control Transfer Statements in Swift

Master continue, break, fallthrough, return, and labeled statements for precise control over loops and switches.

Control FlowIntermediate8 min readJul 8, 2026
Analogies

Introduction

Control transfer statements change the order in which code executes by transferring control from one piece of code to another. Swift provides five of them: continue, break, fallthrough, return, and labeled statements. continue skips the rest of the current loop iteration and moves to the next one. break exits a loop or switch statement entirely. fallthrough explicitly forces a switch case to continue into the next case, since Swift's switch doesn't do this automatically. return exits a function, optionally passing back a value. Labeled statements let you tag a loop with a name so that break or continue can target a specific outer loop from within nested loops.

🏏

Cricket analogy: Looping over each ball of an over, continue is like the umpire calling a no-ball and moving straight to the next delivery; break is calling off play entirely for bad light; fallthrough is like a rain-delay ruling explicitly carrying over into the next session's conditions rather than resetting; return is the innings declaration handing control back to the opposition; and a labeled oversLoop: lets break oversLoop end the entire innings from within a single ball's review.

Syntax

swift
outerLoop: for i in 1...3 {
    for j in 1...3 {
        if j == 2 {
            continue outerLoop
        }
        if i == 3 {
            break outerLoop
        }
        print("i=\(i), j=\(j)")
    }
}

Explanation

A label, like outerLoop:, is placed immediately before a loop's keyword and is followed by a colon. Inside a nested loop, continue outerLoop skips directly to the next iteration of the labeled outer loop rather than the inner one, and break outerLoop exits the outer loop entirely rather than just the inner loop. Without a label, break and continue only affect the innermost enclosing loop or switch. fallthrough is used inside a switch case when you deliberately want execution to continue into the next case's body, bypassing Swift's normal exhaustive-and-exit behavior. return works inside functions to exit immediately, optionally returning a value to the caller.

🏏

Cricket analogy: A label like inningsLoop: sits right before the loop keyword; inside a nested over-by-over loop, continue inningsLoop skips straight to the next innings rather than just the next ball, and break inningsLoop ends the whole match rather than just the current over; without a label, break only stops the innermost over; fallthrough in a switch on match result deliberately carries a 'win' case into the 'net run rate updated' case; and return inside a scoring function exits immediately with the final total.

Example

swift
for number in 1...5 {
    if number == 3 {
        continue
    }
    if number == 5 {
        break
    }
    print(number)
}

switch 2 {
case 1:
    print("one")
case 2:
    print("two")
    fallthrough
case 3:
    print("three")
default:
    print("other")
}

Output

swift
1
2
4
two
three

Key Takeaways

  • continue skips the rest of the current iteration and moves on to the next one.
  • break exits a loop or switch statement immediately and completely.
  • fallthrough explicitly continues execution into the next switch case.
  • return exits a function immediately, optionally returning a value.
  • Labeled statements (e.g. outerLoop:) let break and continue target a specific enclosing loop from nested loops.

Practice what you learned

Was this page helpful?

Topics covered

#Swift#SwiftProgrammingStudyNotes#Programming#ControlTransferStatementsInSwift#Control#Transfer#Statements#Syntax#StudyNotes#SkillVeris