Breaking Out

Noah noah at noah.org
Sat Aug 24 00:56:45 EDT 2002


Simon Faulkner <news at titanic.co.uk> wrote in message news:<tm1dmu44s6eah59fod8st9kmu68svfnimp at 4ax.com>...
> What is the polite way to skip to the end of a long if statement?
> 
> if x ==y:
>   blah
>   blah
>   blah
>   blah
>   blah
>   blah
>   I WANT OUT!
>   blah
>   blah
>   blah
>   blah
> 
> Simon

It is impolite. Presumably your 'I WANT OUT!' point is conditional.
So you put the stuff after 'I WANT OUT!' inside an if or else statement.
The stuff after 'I WANT OUT!' is subordinate to some condition before it.
That stuff gets executed or not depending on 'I WANT OUT!'.
Since that is what you are saying that is what you should write.
If you want it to look less messy (that's a lot of blah...) then
you could pull out some of the code into a function or method.
Long if statements are a bad sign. It is usually a warning sign
that you are writing ugly code.

if x == y:
    blah ()
    blah ()
    blah ()
    blah ()
    blah ()
    blah ()
    if not I_WANT_OUT(): # I WANT OUT!
        blah()
        blah()
        blah()
        blah()

Noah



More information about the Python-list mailing list