是否可以在 Swift 3 中跳过 for-in 循环的迭代?
我想做这样的事情:
for index in 0..<100 {
if someCondition(index) {
index = index + 3 //Skip iterations here
}
}
最佳答案
最简单的方法是在 if 条件中使用 continue
for index in 1...100
{
if index == 5
{
continue
}
print(index)//1 2 3 4 6 7 8 9 10
}
或者
for index in 1...10 where index%2 == 0
{
print(index)//2 4 6 8 10
}
关于swift - 如何跳过 for-in 循环的迭代(Swift 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009118/