Breaking out of nested loops

Justin Sheehy justin at iago.org
Sat Jan 12 09:50:08 EST 2002


"Tal Linzen" <pachy at 012.net.il> writes:

> One feature I miss in python is the ability to break out of nested loops.
> I've searched the newsgroup archives, and found a few threads discussing the
> problem, with no apparent conclusion. The two solutions I've seen -- raising
> an exception, or putting the loop inside a function and using the return
> statement -- are unintuitive (meaning, I didn't come up with them myself
> :-) ).
>
> Know if anyone has drafted a PEP for a syntactic solution for this problem?

Who needs a syntactic solution now that you've found two very good
ways of doing this that already exist?

Both of the strategies you mention are well-known and very effective.

New syntax is only added when there's a really good justification or
when the new syntax is "print >>".  

Further, the print syntax addition is harmless even if it is
unneccesary and ugly, as it doesn't use up a keyword and can't break
any existing working code.

-Justin

 





More information about the Python-list mailing list