nested loops

Oleg Leschov kalmas at udm.ru
Thu Oct 9 10:45:47 EDT 2003


Could there be means of exiting nested loops in python?
something similar to labelled loops in perl..

I consider it irrating to have to make a flag for sole
purpose of checking it after loop if we need to break once more...

So maybe there should be an argument to break that is an int which is
a number of loops to break. So it would default to 1 (or whatever means
the current enclosing loop), not breaking any code...

Or maybe name the loops and give the loop name argument to break:
for i in list as outerloop:
    while 1:
        <do something>
        if u:
            continue
        elif v:
            continue outerloop
        elif w:
            break
        elif x:
            break outerloop
Or both.

Are there any cons to this proposal?






More information about the Python-list mailing list