Breaking out of nested loops

Joshua Muskovitz joshm at taconic.net
Sun Jan 13 04:21:35 CET 2002


"Dietmar Schwertberger" <dietmar at schwertberger.de> wrote in message
news:ant1218220b02%2U at schwertberger.freenet.de...
> IMHO "break n" (default n=1) wouldn't be ugly, at least less ugly than
> the workarounds...
> Example:
> for x in range(10):
>     for y in range(10):
>         for z in range(10):
>             if abc(x,y,z):
>                 break 3

I vote that we should instead implement the INTERCAL statement "returnfrom".
That way, it won't be affected by refactoring.  :-)

More seriously though, I would say either implement a flag to drop out of
the loop (when possible), use exceptions (your own custom ones, to avoid
inadvertantly catching something you weren't supposed to), or restructure
the code to avoid the situation.

-- josh




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list