why I don't like range/xrange
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sun Feb 18 08:59:05 EST 2007
sjdevnull at yahoo.com a écrit :
> Bruno Desthuilliers wrote:
>
>>Roel Schroeven a ecrit :
>>
>>>Bruno Desthuilliers schreef:
>>>
>>>
>>>>stdazi a ecrit :
>>>
>>>
>>>>>for (i = 0 ; i < 10 ; i++)
>>>>> i = 10;
>>>>
>>>>
>>>>for i in range(10):
>>>> i = 10
>>>>
>>>>What's your point, exactly ?
>>>
>>>
>>>In the first iteration, i is set equal to 10. Then, before starting the
>>>second iteration, i is incremented to 11; then the loop condition is
>>>checked and results in false. So the loop terminates after the first
>>>iteration.
>>
>>oops - my bad. But why would one do so when a break would do the trick:
>>for i in range(10):
>> break
>
>
> After the C loop finishes, i is 11. After the python loop-with-break
> finishes, i is 0. That may effect later code.
>
Lord saves me from having to maintain programs based on such
constructions...
More information about the Python-list
mailing list