Swift Continue Statement
The Swift continue statement tells a loop body to immediately stop the current loop iteration and restart the next loop iteration.
Forforloop,continueAfter the statement is executed, the increment statement will still be executed. Forwhileanddo...whileloop,continueThe statement re-executes the conditional judgment statement.
Syntax
The syntax format of the Swift continue statement is as follows:
continue
Flowchart:
Example
import Cocoa
var index = 10
repeat{
index = index + 1
if( index == 15 ){ // index 等于 15 时跳过
continue
}
print( "index 的值为 \(index)")
}while index < 20
The output result of the above program execution is:
index 的值为 11 index 的值为 12 index 的值为 13 index 的值为 14 index 的值为 16 index 的值为 17 index 的值为 18 index 的值为 19 index 的值为 20Other Extensions
Swift Loops