repeat-while
是在 Swift 中才有, Objective-C 時代沒有的。
repeat-while
和其他語言的 do-while
類似。
var index = 10
repeat {
print(index)
}while index < 8
// 10
while index < 10 {
print(index)
}
// 無輸出
不管何種情況
repeat
肯定會執行一次,然後判斷循環條件,這與while
循環剛好相反,這在使用時需要注意。