[Python-ideas] for/except/else syntax
arnodel at googlemail.com
Fri Oct 9 09:22:58 CEST 2009
2009/10/9 Gerald Britton <gerald.britton at gmail.com>:
> The thing is, if you read the documentation, it is not misleading. It
> does just what it says it does. The problem Guido identified, is that
> too many folks don't read the documentation, but try to figure it out
> by reading examples. Small wonder they get confused!
I read the docs as well. In fact, I used to read the docs *every
time* I used the for-else construct. To me, for-else used to be
confusing because although I knew very well that the else clause was
about whether the loop was broken or not, I could never remember which
of the two it was.
It was one of these things that I couldn't learn because although I
knew the dichotomy, I couldn't figure out which half of it the 'else:'
referred to. It's a bit like the difference between the noun 'bow'
which describes the device that throws arrows and the noun 'bow' which
refers to a movement you make in the presence of royalty. I know how
to pronounce them both, I just can't remember which one is which (I'm
not a native english speaker)!
That's why I've come to think of for-else as break-else. It makes it
clear to me that the else clause is executed when the loop *didn't*
More information about the Python-ideas