[Python-ideas] for/else syntax

Gerald Britton gerald.britton at gmail.com
Thu Oct 1 16:21:18 CEST 2009

There is consistency between the use of "else" in for, while and try:
The "else" suite is executed when the for/while/try statement is
exhausted -- that is, is not terminated abnormally  with a break,
return, exception, etc.

Once I got it, I GOT IT! and have found it quite handy.  I don't think
we should talk about changing this syntax for for/while without
including the try statement.  I do believe, though, that the idea is a
non-starter since it would break existing code.

As for the "intuitive" argument, that's a red herring.  One person's
"intuitive" is another's "obscure."  The word is overused and
undefined in any objective, measurable sense.  Steve Ballmer likes it
since he thinks it gives him a leg up on the competition.  That should
be enough for us to eschew its use.

On Thu, Oct 1, 2009 at 9:54 AM, Arnaud Delobelle <arnodel at googlemail.com> wrote:
> 2009/10/1 Antti Rasinen <ars at iki.fi>:
>> I must say that calling for ... else "somewhat unintuitive" is the
>> understatement of the year. The analogy with if ... else leads further
>> astray than Odysseus.
>> The feature itself is not bad. It's just that it is misnamed.
> [...]
>> I don't want the feature to be removed or even renamed (at least before
>> Python 4). But the feature *is* badly named and unintuitive.
> I agree.  I use it from time to time and I used to have to look up the docs
> every time, because I couldn't remember wheteher the 'else:' clause
> meant 'if did break' or 'if didn't break'.
> I solved this problem by stopping thinking about it as while-else or
> for-else, but rather as break-else.
> --
> Arnaud
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

Gerald Britton

More information about the Python-ideas mailing list