Breaking out of nested loops

Jonathan Gardner jgardn at alumni.washington.edu
Sun Jan 13 03:49:04 EST 2002


> > There are not supposed to be such a magical break, to my knowledge no
> > other language support this either. It kind of breaks the good
> > behaviour you expect from a imparative programming language.
>
> Java does support this!
>

Perl has this:

LOOP_A: for ... {
LOOP_B: while .. {
      next LOOP_A if some condition;
      }
     }

It was very easy to understand for me, and I think it made the code a lot 
easier to write and think about. I've used it several times. I think the 
other solutions (flags or exceptions) are a bit too cryptic.

Jonathan




More information about the Python-list mailing list