for what are for/while else clauses

Fredrik Lundh fredrik at
Mon Nov 17 14:59:10 CET 2003

on confused.lang.python, Just wrote:

> > > the fact that the 'controlling condition' is "a break statement
> > > has executed"
> >
> > that's not how it works.
> But it is: the only time the else clause is _not_ executed is when the
> loop was stopped due to a break statement:

the break statement has nothing to do with the else clause; the else
is executed when there's no more item in the sequence.  if you break
or raise or return or yield-and-never-resume or call-and-never-return
your way out of the loop doesn't matter.

read the C code if you don't believe me.

> You're either speaking in tongues, or you're wrong. Am I missing
> something?

like Alex, you're confusing cause and effect.  don't do that; things are
easier to understand if you explain how they actually work.


More information about the Python-list mailing list