无涯教程-Swift - for-in函数

83 阅读1分钟

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

for-in - 语法

SWIFT 4编程语言中for-in循环语法为-

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

for-in - 示例

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
        <h2 id="h22">参考链接</h2><p><a target="_blank" href="https://www.learnfk.com/swift/swift-for-in.html" style="">https://www.learnfk.com/swift/swift-for-in.html</a></p>