Swift Continue Statement
The Swift continue
statement tells a loop to immediately stop the current iteration and start the next one.
For a for loop, the continue statement will still execute the increment statement after execution. For while and do...while loops, the continue statement will re-evaluate the condition.
Syntax
The syntax for the Swift continue
statement is as follows:
continue
Flowchart:
Example
import Cocoa
var index = 10
repeat {
index = index + 1
if index == 15 { // Skip when index is 15
continue
}
print("The value of index is \(index)")
} while index < 20
The output of the above program is:
The value of index is 11
The value of index is 12
The value of index is 13
The value of index is 14
The value of index is 16
The value of index is 17
The value of index is 18
The value of index is 19
The value of index is 20