Evg*_*ban 1 arrays swift
我有100个项目的数组.我想用特定的步骤,2n,3n,4n等迭代它.例如,如果n = 3,我想迭代3,6,9,12个数组元素.
怎么实现呢?谢谢.
Ole*_*huk 5
在Swift中你可以借助它来做到这一点stride.
stride
let n = 3 for index in stride(from: 0, through: 100, by: n) { print(index) }
索引输出:
0 3 6 9 12 15 18 21 24 27 30 33 36 39 42 ...
归档时间:
8 年,11 月 前
查看次数:
277 次
最近记录: