How to break out of two nested for loops?

Michael Kelly mkelly2002NOSPAM at earthlink.net
Fri Jan 25 11:44:12 EST 2002


On 25 Jan 2002 01:00:58 GMT, "Donn Cave" <donn at u.washington.edu>
wrote:

>Now if that's what we want, by analogy but extended to N enclosing
>loops, like "break 2" - then an exception would be a crude substitute.
>I think that would be kind of an awful construct, though - fragile,
>because if you change the loop nesting you have to recalculate all
>the break N's.

Hmmm, intriguing.  How about a pseudo list indexing
syntax where the parser calculates the number of loops and
your break has overloaded '[]' operator so that you can
do something line break[-1] to break out of the outermost
loop, break[-2] the one inside that, break[1] to break out
of the loop immediately enclosing the one the break is
in etc. with the default index being 0 so that 'break' is
equivalent to 'break[0]' just break out of the immediate
loop?? :)




Mike

--

"I don't want to belong to any club that would have me as a member."
    -- Groucho Marx



More information about the Python-list mailing list