Swift Continue Statement

The Swift continue statement skips the remaining statements in the current loop iteration and starts the next iteration. It is useful when a loop should ignore selected values without ending the loop completely.

You can use continue inside a Swift while loop, a Swift repeat-while loop, or a Swift for-in loop. The condition that triggers continue is usually written in an if statement.

How Swift continue changes loop execution

When Swift reaches continue, it does not execute the statements that follow it in the current iteration. Control moves to the loop’s next iteration:

  • In a for-in loop, Swift requests the next value from the sequence.
  • In a while loop, Swift evaluates the loop condition again.
  • In a repeat-while loop, Swift evaluates the condition at the end of the current iteration before deciding whether to repeat.

The Swift break statement ends the loop, whereas continue skips only one iteration. A return statement exits the current function, so it has a wider effect than either loop-control statement.

Swift continue syntax

The standalone syntax is:

</>
Copy
 continue

In a while loop, place continue after the condition that identifies an iteration to skip.

</>
Copy
 while boolean_expression {
     // some statements
     continue
     // some other statements
 }

In a for-in loop, the loop variable automatically advances to the next element after continue.

</>
Copy
 for index in var {
     // some statements
     continue
     // some other statements
 }

The following schematic appears in the original tutorial content:

</>
Copy
 while boolean_expression {
     // some statements
     continue
     // some other statements
 }

For an actual repeat-while loop, use repeat for the body and place the condition after while:

</>
Copy
repeat {
    // statements before continue

    if conditionToSkip {
        continue
    }

    // statements skipped when the condition is true
} while loopCondition

Swift continue example with a while loop

This example skips the value 3. Notice that the counter is incremented before continue. Without that update, the condition i == 3 would remain true and the loop would never progress.

main.swift

</>
Copy
var i = 0

while i < 6 {
   if i==3 {
        i = i + 1
       continue
   }
   print("i : \(i)")
   i = i + 1
}

print("rest of the statements")

Output

$swift while_loop_continue_example.swift
i : 0
i : 1
i : 2
i : 4
i : 5
rest of the statements

The output does not contain i : 3 because the print statement is below continue and is skipped for that iteration.

Swift continue example with a for-in loop

A for-in loop is simpler when iterating over a range because Swift advances the loop variable automatically. The following example ignores 3 and prints the other values.

main.swift

</>
Copy
var i = 0

for i in 1..<6 {
   if i==3 {
       continue
   }
   print("i : \(i)")
}

print("rest of the statements")

Output

$swift for_loop_continue_example.swift
i : 1
i : 2
i : 4
i : 5
rest of the statements

Filtering values with Swift continue in a for-in loop

A common use of continue is to filter values while keeping the loop body easy to read. This example prints only even numbers.

</>
Copy
for number in 1...10 {
    if number.isMultiple(of: 2) == false {
        continue
    }

    print(number)
}

Output

2
4
6
8
10

The guard-style structure keeps the main action at the end of the loop: unwanted values are skipped first, and valid values continue through the remaining statements.

Swift continue example with a repeat-while loop

In a Swift repeat while loop, the body runs before the condition is checked. This example skips printing when i is 3.

main.swift

</>
Copy
var i = 0

repeat {
   if i==3 {
       i = i + 1
       continue
   }
   print("i : \(i)")
   i = i + 1
} while i<5

print("rest of the statements")

Output

$swift repeat_while_loop_break_example.swift
i : 0
i : 1
i : 2
i : 4
rest of the statements

As in the while example, the counter is updated before continue. This prevents the loop from repeatedly processing the same value.

Labeled continue in nested Swift loops

Inside nested loops, an unlabeled continue applies to the innermost loop. Swift also supports statement labels, which let you continue a specific outer loop.

</>
Copy
outerLoop: for row in 1...3 {
    for column in 1...3 {
        if column == 2 {
            continue outerLoop
        }

        print("row \(row), column \(column)")
    }
}

Output

row 1, column 1
row 2, column 1
row 3, column 1

When column becomes 2, continue outerLoop stops the current inner-loop pass and begins the next row iteration.

Swift continue vs break

StatementEffect inside a loopTypical use
continueSkips the rest of the current iteration and proceeds with the loop.Ignore selected values while processing the remaining sequence.
breakEnds the loop immediately.Stop searching after a match or terminate when a condition is reached.
returnExits the current function.Finish the function and optionally return a value.

Use continue when later iterations are still needed. Use break when no further iteration should run.

Common Swift continue mistakes

  • Forgetting to update a while-loop counter: If the update is below continue, that update is skipped and the loop can become infinite.
  • Expecting continue to end the loop: It skips one iteration only. Use break to leave the loop.
  • Placing continue outside a loop: Swift permits continue only within loop statements.
  • Continuing the wrong nested loop: Use a statement label when control must move to an outer loop.
  • Putting required cleanup below continue: Statements below continue do not execute in the skipped iteration, so move required updates above it.

Swift continue frequently asked questions

What does continue do in Swift?

continue stops executing the remaining statements in the current loop iteration and transfers control to the next iteration.

Can Swift continue be used in for-in, while, and repeat-while loops?

Yes. Swift supports continue in for-in, while, and repeat-while loops.

What is the difference between continue and break in Swift?

continue skips only the current iteration, while break terminates the loop entirely.

Why can continue cause an infinite while loop?

If a counter or state update appears after continue, Swift skips that update. The loop condition may therefore remain unchanged and continue indefinitely.

How does labeled continue work in Swift?

A labeled continue, such as continue outerLoop, starts the next iteration of the loop identified by that label. It is mainly used with nested loops.

Swift continue editorial QA checklist

  • Verify that each while and repeat-while example updates its counter before any reachable continue.
  • Confirm that output blocks omit only the values intentionally skipped by continue.
  • Check that continue is described as skipping one iteration, not terminating the loop.
  • Confirm that nested-loop examples identify whether an unlabeled or labeled continue is used.
  • Run new Swift examples with a current Swift compiler and confirm that range and string-interpolation syntax compile.

Using Swift continue safely

The Swift continue statement is appropriate when a loop should ignore selected inputs and keep processing later values. In counter-controlled loops, update the counter or loop state before continue. In nested loops, use a label when the next iteration must belong to an outer loop. For more control-flow examples, see this Swift Tutorial.