9.18. Swift for cycle

发布时间 : 2025-10-25 13:33:48 UTC      

Page Views: 9 views

This loop has been deprecated in Swift 3.

Swift for a loop is used to repeat a series of statements until a specific condition is reached, usually by increasing the value of the counter after each loop is completed.

9.18.1. Grammar #

Swift for the syntax format of the loop is as follows:

for init; condition; increment{ loop body } 

Parameter resolution:

  1. init will be executed first, and only once. This step allows you to declare and initialize any loop control variables. You can also not write any statements here, as long as a semicolon appears.

  2. Next, it will judge condition . If true, the loop body is executed. If false, the loop body is not executed, and the control flow jumps to the following for the next statement of the loop.

  3. After the execution for after looping the body, the control flow jumps back to the increment statement. This statement allows you to update loop control variables. This statement can be left blank as long as a semicolon appears after the condition.

  4. The conditions are judged again. If true, the loop is executed, and the process is repeated over and over again (loop body, then increase the step value, and then re-determine the condition). The for loop terminates when the condition becomes false.

Flow chart:

Image0

9.18.2. Example #

import Cocoa var someInts:[Int] = [10, 20, 30] for var index = 0; index < 3; ++index { print( "The value corresponding to the index [\(index)] is \(someInts[index])") } 

The output of the above program execution is as follows:

The value corresponding to index [0] is 10 The value corresponding to index [1] is 20 The value corresponding to index [2] is 30 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。