Swift 在循環中的控制語句
控制語句在循環中使用,用于改變執行順序。愛掏網 - it200.com當執行離開作用域時,自動創建的所有對象都會被銷毀。愛掏網 - it200.com
Swift 4支持的控制語句列表:
Swift 4中的 continue 語句用于停止當前正在執行的語句,并從下一次循環迭代的開始處重新開始。愛掏網 - it200.comcontinue語句可配合for循環、while循環和do…while循環使用。愛掏網 - it200.com
對于 for 循環,continue語句檢查條件并增加循環的部分以執行。愛掏網 - it200.com
對于 while和do…while 循環,continue語句將程序控制傳遞給條件測試。愛掏網 - it200.com
語法
Swift 4循環中continue語句的語法如下:
continue
Swift 4的continue語句的流程圖
示例
var index = 10
repeat {
index = index + 1
if( index == 25 ){
continue
}
print( "Value of index is \(index)")
} while index < 30
輸出:
Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 15
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
Value of index is 21
Value of index is 22
Value of index is 23
Value of index is 24
Value of index is 25
Value of index is 26
Value of index is 27
Value of index is 28
Value of index is 29
Value of index is 30
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。