开发者

skip a parent loop from a loop inside for loop in python [duplicate]

开发者 https://www.devze.com 2023-03-22 16:12 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Python: Continuing to next开发者_JAVA技巧 iteration in outer loop
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Python: Continuing to next开发者_JAVA技巧 iteration in outer loop

Maybe the title is kind of confusing but you will understand what i mean in the code:

for item in items: #i want to skip one loop of this bucle
    for i in item: #loop nº2
        if i==5:
            continue #but this only skip a loop in nº2, there's no propagation

How can i get this to work? Thanks in advance.


Set a flag, break out of the inner loop, check the flag in the main loop, and continue as appropriate.

  for i = 1 to N do
     flag = false
     for j = 1 to M do
        ...
        if condition then
           flag = true
           break
        ...
     if flag then continue
     ...
0

精彩评论

暂无评论...
验证码 换一张
取 消