当前位置: 首页 > 文档资料 > Swift 中文教程 >

for-in

优质
小牛编辑
116浏览
2023-12-01

for-in循环遍历项目集合,例如数字范围,数组中的项目或字符串中的字符 -

语法 (Syntax)

Swift 4编程语言中for-in循环的语法是 -

for index in var {
   statement(s)
}
For-In循环

Example

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