History question about for .. else

Andrew Dalke dalke at acm.org
Wed Nov 8 04:05:18 EST 2000


Dave Cole wrote:
>I would be interested in knowing the history behind the introduction
>of the else clause on the for loop.

As I recall from some years ago, Guido said that this is one of the
few parts of Python syntax he did not get from another language.
Instead, it was driven by the implementation similarity to the try
block.

I tried searching for this reference but can't find it.  I know
he said something towards this effect, but searches for "guido", "try",
"for" and "else" give quite a few documents.

Hah!  Given over a half an hour of searching (you better thank me for
that :) I dug up the thread "Origin of for/try ... else" started by
Jeremy Henty (see http://www.egroups.com/message/python-list/30573).
Guido's response is at http://www.egroups.com/message/python-list/30696
and is

Guido on Jan 12, 1998 said:
] I believe this is one of the few language features of Python that I
] didn't steal from some other language :-) Glad you like it. I think
] the discovery of the feature happened at the time I was figuring out
] how to write code for the while statement; I noticed that it looked a
] lot like the if statement and figured that I could add an else clause
] to the while statement with very little effort. It hasn't proven very
] useful, however...

So I was slightly mistaken as to its origin, but close enough!

                    Andrew
                    dalke at acm.org








More information about the Python-list mailing list