在 Swift 編程語(yǔ)言中的 continue 語(yǔ)句告訴循環(huán)停止正在執(zhí)行的語(yǔ)句,并在循環(huán)下一次迭代重新開(kāi)始。
對(duì)于 for 循環(huán),continue 語(yǔ)句使得循環(huán)的條件測(cè)試和增量部分來(lái)執(zhí)行。對(duì)于 while 和 do ... while 循環(huán),continue 語(yǔ)句使程序控制轉(zhuǎn)到條件測(cè)試。
在 Swift 中的 continue 語(yǔ)句的語(yǔ)法如下:
continue

import Cocoa
var index = 10
do{
index = index + 1
if( index == 15 ){
continue
}
println( "Value of index is \(index)")
}while index < 20
當(dāng)上述代碼被編譯和執(zhí)行時(shí),它產(chǎn)生了以下結(jié)果:
Value of index is 11 Value of index is 12 Value of index is 13 Value of index is 14 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