如何在循环中进行双重'继续'?

iTa*_*ayb 2 python

是否有可能进行双重继续并跳转到python列表中下一项之后的项目?

ick*_*fay 7

不是真的,但你可以使用一个变量continue在第一次继续之后再次告诉它:

continue_again = False
for thing in things:
    if continue_again:
        continue_again = False
        continue
    # ...
    if some_condition:
        # ...
        continue_again = True
        continue
    # ...
Run Code Online (Sandbox Code Playgroud)


sen*_*rle 5

使用迭代器:

>>> list_iter = iter([1, 2, 3, 4, 5])
>>> for i in list_iter:
...     print "not skipped: ", i
...     if i == 3:
...         print "skipped: ", next(list_iter, None)
...         continue
... 
not skipped:  1
not skipped:  2
not skipped:  3
skipped:  4
not skipped:  5
Run Code Online (Sandbox Code Playgroud)

使用next内置的默认值None避免提高StopIteration- 感谢kevpie的建议!