Jeffrey Barish  <[EMAIL PROTECTED]> wrote:
>Terry Reedy wrote:
>> A for-loop is equivalent to a while loop with the condition 'iterator is
>> not exhausted'.  So do_else when that condition is false -- the iterator
>> is exhausted.
>I think that this is the most important statement in this thread.  As others
>have expressed, I too found for-else surprising when I first encountered
>it.  It made sense to me when I analogized for with if: [ ... ]

And to pull those two together, I found while-else comprehensible by
analogy with if-else:

while stmt:
    do_something() # stmt is True
else:
    do_something_else() # stmt is False

I don't think I've ever used a for-else in the wild, but I have used
while-else. And knowing how that works, it's kind of obvious what
for-else does.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to