Swift 基礎教程:repeat-while 循環

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 循環剛好相反,這在使用時需要注意。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章