Breaking Out
Mahrt, Dallas
dallasm at aiinet.com
Fri Aug 23 18:47:11 EDT 2002
Here is an ugly answer
EscapeException = "HACK"
try:
if foo:
blah
blah
if some_condition:
raise EscapeException
blah
blah
blah
except EscapeException:
pass
> -----Original Message-----
> From: James Kew [mailto:james.kew at btinternet.com]
> Sent: Friday, August 23, 2002 6:03 PM
> To: python-list at python.org
> Subject: Re: Breaking Out
>
>
> "Bradley D. Larson" <blarson at crary.com> wrote in message
> news:mailman.1030131895.10485.python-list at python.org...
>
> > I believe a cleaner method is:
> >
> > while x = y:
> > blah
> > blah
> > blah
> > if break_now:
> > break
> > blah
> > blah
> > blah
> > if break_now:
> > break
> > blah
> > blah
> > blah
> > [...]
> > break # dont forget the last break!
>
> That makes a conditional look like a loop -- not terribly
> expressive of intent.
>
> "Skip to the end" and "I WANT OUT" suggest throwing an
> exception to me...
>
> --
> James Kew
> james.kew at btinternet.com
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list