1.5.2 for: else:

Doug Landauer landauer at apple.com
Fri Jul 30 13:45:45 EDT 1999


> for an "if" statement, "else" is a path taken if the
>    expression evaluates to false.

In my mind, for an "if" statement, "else" is the path taken
when the BODY is not executed at all.

> 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.

And therefore, the "else:" on either while or for loops, as
defined in Python, is completely counterintuitive.

> not that complicated, was it?

It's not complicated, it's just something that is easily
open to multiple interpretations, depending on how one views
the normal, common usage of the word.  As such, it is one of the
very few things in Python that (for some of us) is not clear from
context -- it just doesn't look obvious what the behavior should
be.  So, in the spirit of python, we don't use it.  Unfortunately,
others do.  I hope no one ever uses it without a comment explaining
what it means.

I know it ain't gonna change soon; but one can hope that perhaps
Python 2.0 could choose a better keyword for it -- one that doesn't
come with preconceived notions that the current definition violates.
-- 
    Doug Landauer        landauer at apple.com (work)
                         landauer at scruznet.com (not-work)




More information about the Python-list mailing list