Swift Continue 語(yǔ)句
Swift continue語(yǔ)句告訴一個(gè)循環(huán)體立刻停止本次循環(huán)迭代,重新開始下次循環(huán)迭代。
對(duì)于 for 循環(huán),continue 語(yǔ)句執(zhí)行后自增語(yǔ)句仍然會(huì)執(zhí)行。對(duì)于 while 和 do...while 循環(huán),continue 語(yǔ)句重新執(zhí)行條件判斷語(yǔ)句。
語(yǔ)法
Swift continue語(yǔ)句的語(yǔ)法格式如下:
continue
流程圖:

實(shí)例
import Cocoa var index = 10 repeat{ index = index + 1 if( index == 15 ){ // index 等于 15 時(shí)跳過(guò) continue } print( "index 的值為 \(index)") }while index < 20
以上程序執(zhí)行輸出結(jié)果為:
index 的值為 11 index 的值為 12 index 的值為 13 index 的值為 14 index 的值為 16 index 的值為 17 index 的值為 18 index 的值為 19 index 的值為 20
更多建議: