Swift for-in循环
for-in 循环遍历项目的集合,例如数字范围、数组中的项目或字符串中的字符−
语法
Swift 4编程语言中 for-in 循环的语法是−
for index in var {
statement(s)
}
示例
var someInts:[Int] = [10, 20, 30]
for index in someInts {
print( "Value of index is \(index)")
}
当执行上述代码时,产生以下结果:
Value of index is 10
Value of index is 20
Value of index is 30