[Python-ideas] for/else syntax

Yuvgoog Greenle ubershmekel at gmail.com
Fri Oct 2 15:54:36 CEST 2009


On Fri, Oct 2, 2009 at 4:46 PM, Gerald Britton <gerald.britton at gmail.com>
 wrote:

> I can't imagine why I'm still commenting on this thread, since there
> is no chance that Python will remove the "else" from for/while or put
> conditions on it, but here is an example of a use that has no break
> statement:
>
> for i, j in enumerate(something):
>  # suite
>  i += 1
> else:
>  i = 0
>
> # i == number of things processed
>
>
Sorry, there must be some typo in your code. The "i" is always 0 after the
loop unless you break.

>>> for i, j in enumerate(range(10)):
...     i +=1
... else:
...     i = 0
...
>>> i
0
>>>

Also, why would one increment the enumeration index "i" by hand?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20091002/b45c5d0c/attachment.html>


More information about the Python-ideas mailing list