相关疑难解决方法(0)

转到java中的For循环中的下一个迭代

在java中有一个令牌跳过for循环的其余部分吗?类似VB的继续 java.

java for-loop

162
推荐指数
4
解决办法
21万
查看次数

如何在python中跳过单循环迭代?

我有以下代码:

for i in list1:
    if i == 5:
        #skip the NEXT iteration (not the end of this one)
    else:
        #do something
Run Code Online (Sandbox Code Playgroud)

如何跳过抛出跳过的迭代后的迭代.例如,如果list1=[1, 2, 3, 4, 5, 6, 7],循环将跳过6并直接转到7因为5触发跳过我已经看到了这个问题和其他几个,但它们都处理跳过当前迭代,而我想跳过一次迭代.这些问题的答案表明continue,据我所知,这将停止当前迭代的剩余部分并继续下一个问题,这不是我想要的.如何在循环中跳过单个迭代?

编辑:使用next()已被建议,但这对我不起作用.当我运行以下代码时:

a = [1, 2, 3, 4, 5, 6, 7, 8]
ai = iter(a)
for i in a:
    print i
    if i == 5:
        _ = next(ai)
Run Code Online (Sandbox Code Playgroud)

我明白了

1
2
3
4
5
6 #this should not be …
Run Code Online (Sandbox Code Playgroud)

python iteration loops

2
推荐指数
1
解决办法
8062
查看次数

标签 统计

for-loop ×1

iteration ×1

java ×1

loops ×1

python ×1