History question about for .. else

Dave Cole djc at object-craft.com.au
Wed Nov 8 02:06:16 CET 2000

I just used the else clause on a for loop for the first time and my
business partner does not like it.  We launched into a discussion
about the construct.

        for value in list:
            if condition:
                # do something
            # do something else

My partner is of the opinion that the syntax is ugly, and he would
avoid it if at all possible.  I argued that it is a zero-cost
detection of "falling of the end of the loop" as it prevents you
having to use an additional condition variable and subsequent test.

I would be interested in knowing the history behind the introduction
of the else clause on the for loop.

- Dave


More information about the Python-list mailing list