for what are for/while else clauses

Just just at xs4all.nl
Mon Nov 17 07:28:48 EST 2003


In article <mailman.787.1069069214.702.python-list at python.org>,
 "Fredrik Lundh" <fredrik at pythonware.com> 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:

  >>> for x in []:
  ...   print x
  ... else:
  ...   print "else"
  ... 
  else
  >>> for x in [1]:
  ...   print x
  ... else:
  ...   print "else"
  ... 
  1
  else
  >>> for x in [1]:
  ...   print x
  ...   break
  ... else:
  ...   print "else"
  ... 
  1
  >>> 

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

Just




More information about the Python-list mailing list