小编mir*_*doh的帖子

如何在Swift中跳过for循环中的索引

我试图跳过随机条件,如果为true,将跳过循环,但结果是打印0,1,2,3,4 我在Java中知道的所有元素,如果索引增加索引将跳过,但这不会发生Swift.

更新:这是我编写的某个程序的简化版本,print()必须在每个循环之后立即发生,并且索引仅在某些未知条件下递增,我希望它的行为类似于JAVA.

for var index in 0..<5 {
  print(index)//this prints 0,1,2,3,4, this must happen right after for loop
  if some unknown condition {
      index+=1
  }
}
Run Code Online (Sandbox Code Playgroud)

iteration for-loop ios swift

12
推荐指数
3
解决办法
1万
查看次数

标签 统计

for-loop ×1

ios ×1

iteration ×1

swift ×1