Swift break語句
Swift 4中的break語句用于以下兩種情況:
- 當(dāng)需要立即終止循環(huán)語句時(shí)使用break語句。愛掏網(wǎng) - it200.com程序控制在循環(huán)后的下一條語句繼續(xù)執(zhí)行。愛掏網(wǎng) - it200.com
- 也用于終止switch語句中的某個(gè)case。愛掏網(wǎng) - it200.com
在嵌套循環(huán)中,break語句終止最內(nèi)層的循環(huán),并開始執(zhí)行代碼塊后的下一行。愛掏網(wǎng) - it200.com
語法
Swift 4中break語句的語法如下:
break
Swift 4 break語句的流程圖
示例
var index = 10
repeat {
index = index + 1
if( index == 25 ){
break
}
print( "Value of index is \(index)")
} while index < 30
輸出:
Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 15
Value of index is 16
Value of index is 17
Value of index is 18
Value of index is 19
Value of index is 20
Value of index is 21
Value of index is 22
Value of index is 23
Value of index is 24
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。