在 Swift 編程語言中的 continue 語句告訴循環(huán)停止正在執(zhí)行的語句,并在循環(huán)下一次迭代重新開始。
對于 for 循環(huán),continue 語句使得循環(huán)的條件測試和增量部分來執(zhí)行。對于 while 和 do ... while 循環(huán),continue 語句使程序控制轉(zhuǎn)到條件測試。
在 Swift 中的 continue 語句的語法如下:
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í)行時,它產(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