Newbie getting desperate with for

Michael Torrie torriem at
Fri Feb 18 17:54:02 CET 2011

On 02/17/2011 04:10 PM, Werner wrote:
> It is meant to put load on a CPU, RAM and disk (swap). The code now
> looks like this:
> #!/usr/bin/python
> while True:
>     i = 0
>     for i in range(20000000):
>         break

Just for your information, your code is the equivalent of:

while True:
    temp = range(20000000)

The for loop does absolutely nothing in your case.  After the range is
computed, the for loop exits on the first iteration.

On python 3.0 range() is a generator so your code essentially distills
down to this if you ran it on python 3:

while True:

More information about the Python-list mailing list