breaking out of outer loops

Paul Rubin http
Tue Jan 29 21:27:01 CET 2008


noemailplease0001 at gmail.com writes:
> Any elegant way of breaking out of the outer for loop than below, I
> seem to have come across something, but it escapes me
> 
> for i in outerLoop:
>    for j in innerLoop:
>        if condition:
>           break
>    else:
>        continue
>     break

You can do it with a try/except/raise statement but I generally prefer
to wrap both loops in a function and use a "return" statement.



More information about the Python-list mailing list