why I don't like range/xrange

sjdevnull at yahoo.com sjdevnull at yahoo.com
Sat Feb 17 15:01:53 EST 2007


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.




More information about the Python-list mailing list