[Tutor] Break, multiple loops

Emile van Sebille Emile van Sebille" <emile@fenx.com
Sat, 27 Nov 1999 07:16:57 -0800


Neil,

I'm not sure if this is a 'clean' way to do it, but it is clear...

try:
    while 1:
        while 2:
            dostuff()
            raise "Exitting..."
except "Exitting...":
    pass

Emile van Sebille
emile@fenx.com
-------------------


----- Original Message -----
From: Neil Conway <neilconway@home.com>
To: <tutor@python.org>
Sent: Friday, November 26, 1999 9:07 PM
Subject: [Tutor] Break, multiple loops


> Hello all.
>
> I was wondering - is there a way to break cleanly out of multiple
loops? The
> exact same as a 'break' statement, but out of *all* loops. i.e
> ---
> while 1:
>         while 2:
>                 super_break
> ---
> A normal break statement just leaps out of the first 'while' (if I'm
not
> mistaken). I would like a statement that leaps out of both loops.
>
> In 'Programming Python' (pg. 193), they have a somewhat similar
dilemma, and
> they use an 'exitflag' variable to check if the first loop has been
broken, and
> if it has, execute another 'break'. This seems messy to me: isn't
there a
> better way? Especially if I want to leap out of, say, 10 loops with 1
> 'super_break' statement.
>
> Thanks in advance,
>
> Neil Conway
>
> ----------------------------------
> E-Mail: Neil Conway <neilconway@home.com>
> Date: 27-Nov-1999
> Time: 00:00:22
>
> This message was sent by XFMail
> ----------------------------------
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor
>
>