📅  最后修改于: 2020-12-25 04:27:12             🧑  作者: Mango
在某些情况下,您需要多次执行一个代码块。通常,语句是按顺序执行的:函数的第一个语句首先执行,然后第二个执行,依此类推。
编程语言提供了各种控制结构,允许更复杂的执行路径。
循环语句使我们可以多次执行一个语句或一组语句。以下是大多数编程语言中循环语句的概述-
Swift 4编程语言提供了以下几种循环来处理循环需求。单击以下链接以查看其详细信息。
Sr.No | Loop Type & Description |
---|---|
1 | for-in
This loop performs a set of statements for each item in a range, sequence, collection, or progression. |
2 | while loop
Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. |
3 | repeat…while loop
Like a while statement, except that it tests the condition at the end of the loop body. |
循环控制语句从其正常顺序更改执行。当执行离开作用域时,在该作用域中创建的所有自动对象都将被销毁。
Swift 4支持以下控制语句。单击以下链接以查看其详细信息。
Sr.No | Control Statement & Description |
---|---|
1 | continue statement
This statement tells a loop to stop what it is doing and start again at the beginning of the next iteration through the loop. |
2 | break statement
Terminates the loop statement and transfers execution to the statement immediately following the loop. |
3 | fallthrough statement
The fallthrough statement simulates the behavior of Swift 4 switch to C-style switch. |