why no break N levels, as in other leading languages?

Skip Montanaro skip at pobox.com
Thu May 1 21:42:30 EDT 2003


Dan> Anyway, in python did he forget about giving it a N ability or is there
Dan> of course some higher principle involved?

Aahz> class BreakException(Exception):
Aahz>     pass
Aahz> 
Aahz> try:
Aahz>     for i in range(foo):
Aahz>         for j in range(bar):
Aahz>             for k in range(spam):
Aahz>                 if my_func():
Aahz>                     raise BreakException
Aahz> except BreakException:
Aahz>     pass

Cameron> I salute Aahz by summarizing in English: YES, Python offers a
Cameron> strictly more expressive model.  She aptly exemplifies it above.

Also, if you need to break out of a triply nested loop you may want to
consider an algorithm redesign anyway. ;-)

Skip





More information about the Python-list mailing list