for what are for/while else clauses

Erik Max Francis max at alcyone.com
Mon Nov 17 15:57:16 EST 2003


Fredrik Lundh wrote:

> you mean you don't know how the for-loop checks if there's
> another item in the sequence?
> 
> (hint: look for StopIteration in the docs)

This hardly seems like a very good mnemonic, since the for...else
construct predates iterators.

The whole point here is that the behavior of for...else isn't
intuitively obvious.  Sure, you can rationalize it after the fact, but
you have to be familiar with that rationalization to claim it makes
intuitive sense.

In the face of language rejections like try...except...finally,
for...else does not at all seem like something that is intuitively
obvious.  (There's no doubt it's useful, but it's hardly transparent.)

-- 
   Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
 __ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/  \ 
\__/ It's only love that gets you through
    -- Sade




More information about the Python-list mailing list