Swift Continue Statement
The Swift continue statement tells a loop body to stop the current iteration immediately and start the next one.
For for a for loop, thecontinue After the statement executes, the increment statement still executes. For while and do...while a for loop, thecontinue statements, the condition statement is re-executed.
Syntax
The syntax of the Swift continue statement is as follows:
continue
Flow diagram:
Example
import Cocoa
var index = 10
repeat{
index = index + 1
if( index == 15 ){ // index 等于 15 时跳过
continue
}
print( "index 的值为 \(index)")
}while index < 20
The output of the above program is:
index 的值为 11
index 的值为 12
index 的值为 13
index 的值为 14
index 的值为 16
index 的值为 17
index 的值为 18
index 的值为 19
index 的值为 20
Swift Loops