Python double while loop not working, can't figure why
<p>I understand that maybe with the use of "for" the code could be clear, but I would like to understand why this code isn't working.
Also, the code is an adaptation for a 2008 MIT OCW class exercise in which the only functions that are allowed for use are the arithmetic ones, if, elif, else, print and while.
Just to point it out, the code was supposed to print out the first 1000 prime numbers. </p>

<pre><code>print '2, '      #Print the prime 2 to set only odd primes.
primesofar=3     #Set 3 as the first prime
primecounter=1   #Mark 3 as the first prime to test until 1000, otherwise the while below should test to 1001
primesupport=1   #Create primesupport with a integer value
while primecounter&lt;1000:
    primesupport=primesofar/2  #Create a support counter for test the prime. This counter only had to have the half value of the supposed prime, because we only need to try to divide by the primes that are lower than the half of the suppposed prime. In fact it would be better to test for values that are lower than the square root of the supposed prime, but we can't use square root operation yet.
    while primesupport&gt;0:
      if primesofar%primesupport == 0:
        primesupport=-1       #If the remainer of the division is 0, the number isn't prime because it will have more than two divisors so we set primesupport as -1 to exit the while and increase the current primesofar to the next odd number.
        primesofar=primesofar+2
      elif primesupport==1:   #If primesupport is 1, we tested all the numbers below the half of the supposed prime which means the number is prime. So we print it, set the while exit and increase the number of primes counted and go to the next odd number.
        print primesofar+', '
        primesofar=primesofar+2
        primesupport=-1
        primecounter=primecounter+1
      else: 
        primesupport=primesupport-1
</code></pre>

<p>I am thankfully for the fast responses and now I think that maybe there was a break in the code that I can't see. Because of this, I will try to write down what I think that the code was supposed to do in order to make it easier for you to point out where I am making a mistake.
Let's start:
primesofar receives 3; primecounter receives 1 and primesupport receives 1.
The first while test primecounter and since primesupport is less than 1000, it enters the loop.
Then, primesupport value is changed to 1 because 3/2=1
Since primesupport is greater than 0, it enters in the second while loop.
The if condition is true (3%1=0) so the code enter the if, change the primesupport to -1 and increase primesofar by two.(now primesupport=-1 and primesofar=5)
Here is has a problem because it leaves without printing 3, but let's continue.
When it goes back to the second while it will receive a False, since -1 is not greater than 0.
That will make the code test the first while and since primecounter was not changed, it will enter the loop again.
Primesupport will now receive 2 (because 5/2=2)
It will enter the second loop and pass throught all of it until the else condition.
Primesupport will be decreased by one( primesupport now =1) and the while loop will continue  entering in the elif now.
That will print 5
increase primesofar to 7
decrease primesupport to leave the while loop and increase primecounter, going back to the first loop and start again.
I confess that besides the 3 that is not being printed as expected, i can't see where i am making a mistake here. Hope you could point me out.</p>

<p>Thank you all for the help, especially FallenAngel, John Machin , DiamRem and Karl Knechtel for pointing out the error and by showing a debug method.</p>
