1.5.2 for: else:

Hans Nowak hnowak at cuci.nl
Thu Jul 29 01:43:38 EDT 1999


> William Tanksley <wtanksle at dolphin.openprojects.net> wrote:
> > The very worst part of the current else: behavior is that it changes the
> > meaning of else.  In other constructs, else is an alternate path to take
> > if the data being tested fails a single expression test.  In this
> > contruct, else is a path taken if the code block belonging to the
> > previous test executes a certain instruction.
> 
> nope.  you've got it all backwards.  consider this:
> 
>     for an "if" statement, "else" is a path taken if the
>     expression evaluates to false.
> 
>     for a "while" statement, "else" is a path taken if the
>     expression evaluates to false.  or in other words,
>     when the loop terminates by natural causes.
> 
>     for a "for" statement, "else" is a path taken when
>     there are no more elements to loop over.  or
>     in other words, when the loop terminates by
>     natural causes.
> 
> not that complicated, was it?

I think quite a few people would expect only one of the parts to 
execute, like in if..else, and not both of them. So this extension of 
the meaning of 'else' may come as a surprise for those (including me, 
actually).

But, the feature itself is nice, and the keyword is not going to 
change, is I guess it's no use whining about it. ^_^

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
Python Snippets: http://www.hvision.nl/~ivnowa/snippets/
The Purple Kookaburra Forum: http://www.delphi.com/kookaburra/




More information about the Python-list mailing list