[Tutor] while statement

Sean 'Shaleh' Perry shalehperry@attbi.com
Thu May 1 23:20:01 2003


>
> Another method is the for loop, it will save you the manual
> incrementing of n:
>
> for n in range(1, N+1):
>     do_stuff
>
> range(x, y) creates a list with the integer elements i, where x <= i < y,
> and the for loop will iterate through each element in this list,
> assigning the current element to n.
>

I personally find this horribly wasteful.  xrange() at least generates the 
next element when it is needed.

range(1,100) # builds a 100 item list, ick.

Sure this is a scripting language, but no need to waste cycles uselessly.