[Python-ideas] for/else syntax

Stephen J. Turnbull stephen at xemacs.org
Sat Oct 3 17:49:47 CEST 2009


Gerald Britton writes:
 > Sory Carl, I did NOT get it dead wrong.  The else is executed if the
 > for loop falls through.

 > for i, j in enumerate(something):
 >   # do something
 >   i += 1
 > else:
 >  i = -1

Carl's point (revised to correspond to the new example) is

    assert(i == -1)

so

 > if i > 0:
 >   # we did something

is dead code.



More information about the Python-ideas mailing list