如何跳过for-in循环的迭代(Swift 3) [英] How to skip iterations of a for-in loop (Swift 3)

查看:369
本文介绍了如何跳过for-in循环的迭代(Swift 3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Swift 3中是否可以跳过for-in循环的迭代?

Is it possible to skip iterations of a for-in loop in Swift 3?

我想做这样的事情:

for index in 0..<100 {
    if someCondition(index) {
        index = index + 3 //Skip iterations here
    }
}

推荐答案

简单的while循环即可

Simple while loop will do

var index = 0

while (index < 100) {
    if someCondition(index) {
        index += 3 //Skip 3 iterations here
    } else {
        index += 1
        // anything here will not run if someCondition(index) is true
    }
}

这篇关于如何跳过for-in循环的迭代(Swift 3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆