why I don't like range/xrange
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Sat Feb 17 13:40:33 EST 2007
Roel Schroeven a écrit :
> Bruno Desthuilliers schreef:
>
>> stdazi a écrit :
>
>
>>> 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
>
> So, the point is that in C you can influence the loop's behavior by
> modifying the loop variable, while you cannot do that in Python (at
> least not in a for-loop).
A good thing IMHO.
> In other words, the point is that you can't translate loops literally
> from C to Python. Which is nothing new, and I fail to see how that is
> supposed to be a disadvantage.
>
<aol />
More information about the Python-list
mailing list