Swift Break statement
Swift break statement will immediately end execution of the entire control flow.
If you are using a nested loop (ie a loop nested inside another loop), break statement to stop the execution of the innermost loop, and then start the next line of code after the block.
grammar
Swift break statement syntax is as follows:
break
flow chart:
Examples
import Cocoa var index = 10 repeat{ index = index + 1 if( index == 15 ){ // index 等于 15 时终止循环 break } print( "index 的值为 \(index)") }while index < 20
The above program execution output is:
index 的值为 11 index 的值为 12 index 的值为 13 index 的值为 14