Breaking Out

Bradley D. Larson blarson at crary.com
Fri Aug 23 21:43:04 CEST 2002


With the previously mentioned method you could end up
with nested IFs.

if x ==y:
    blah
    blah
    blah
    if not break_now:
        blah
        blah
        blah
        if not break_now:
            blah
            blah
            blah

and so on...

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!


"James J. Besemer" wrote:

> Sean 'Shaleh' Perry wrote:
>
> > On Friday 23 August 2002 12:04 pm, Simon Faulkner wrote:
> > > What is the polite way to skip to the end of a long if statement?
> >
> > 'break' is the statement you want.
>
> BZZZZZZZZIT!  Wrong.
>
> Break doesn't break an if.
>
> YOu need a goto.  Wait, isn't one.
>
> I suppose you have to say:
>
>     if x==y:
>         pass
>         pass
>         pass
>         if dont want out:
>             pass
>             pass
>             pass
>             pass
>
> After all, you DO have to somehow decide when you want out, no?
>
> Regards
>
> --jb
>
> >
> >
> > --
> > http://mail.python.org/mailman/listinfo/python-list
>
> --
> James J. Besemer  503-280-0838 voice
> http://cascade-sys.com  503-280-0375 fax
> mailto:jb at cascade-sys.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: blarson.vcf
Type: text/x-vcard
Size: 400 bytes
Desc: Card for Bradley D. Larson
URL: <http://mail.python.org/pipermail/python-list/attachments/20020823/00f5164a/attachment.vcf>


More information about the Python-list mailing list