9.17. Swift for-in cycle

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

Page Views: 9 views

Swift for-in loops are used to traverse all the elements in a collection, such as intervals represented by numbers, elements in an array, and characters in a string.

9.17.1. Grammar #

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

for index in var { loop body } 

Flow chart:

Image0

9.17.2. Example 1 #

import Cocoa for index in 1...5 { print("\(index) multiplying by 5 is:\(index * 5)") } 

The element used for traversal in the example is a numerical range from 1 to 5 represented by the closed interval operator (…).

The output of the above program execution is as follows:

Multiplying 1 by 5 is: 5 Multiplying 2 by 5 is: 10 Multiplying 3 by 5 is: 15 Multiplying 4 by 5 is: 20 Multiplying 5 by 5 is: 25 

9.17.3. Example 2 #

import Cocoa var someInts:[Int] = [10, 20, 30] for index in someInts { print( "The value of index is \(index)") } 

The output of the above program execution is as follows:

The value of index is 10 The value of index is 20 The value of index is 30 
《地理信息系统原理、技术与方法》  97

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