History question about for .. else

Dave Cole djc at object-craft.com.au
Tue Nov 7 20:06:16 EST 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
                break
        else:
            # 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

-- 
http://www.object-craft.com.au



More information about the Python-list mailing list