for loop stuck and not interating (Python 3)
<p>I'm currently working on a small script that aims to find taxicab numbers. There is only one small problem, the for loop doesn't increment the variable x and is stuck looping forever. I'll paste the relevant part of the code below:</p>

<pre><code>n = int(10)
counter = int(0)
m = int(m)
x = int(1)
y = int(n**(1/3))
cheatsheet = []

while counter in range(0,m):
    for x in range(1,y):
        if x**3 + y**3 &lt; n:
            print('less than')
            print(x,y,n)
            continue
        elif x**3 + y**3 &gt; n:
            print('greater than')
            y -= 1
            continue
        elif x &gt; y:
            if n in cheatsheet:
                print('counting')
                counter = counter+1
                #checking if n occurs in the list, if so it will add 1 to the counter so that the program will know when to stop
            n = n + 1
            y = int(n**(1/3))
            x = 1
            print('break1')
            #resetting values and bumping n so that it will continue the quest to find 'em all
            break
        else:
            if x and y == 1:
                #this is an error correction for low n values, i mean really low it might be redundant by now
                n = n + 1
                y = int(n**(1/3))
                x = 1
                print('break2')
                break
            cheatsheet.append((n,x,y))        
print(cheatsheet)
</code></pre>

<p>This yields the following result in a terminal window:
<a href="http://i.imgur.com/Luq8vL8.png" rel="nofollow">image</a></p>

<p>Note that I killed the process by myself, the program did not.
As you can tell, the script just loops around and prints 'less than' and the values for x,y,n.</p>

<p>Help is greatly appreciated!</p>

<p>EDIT: the variable m is given by the user, but not included in this bit of code.</p>

<p>This has a number of issues wrong with it I'm not willing to post functional code but I will point some of the issues out. </p>

<p>For starters:</p>

<pre><code>n = int(10)
</code></pre>

<p>isn't required, not an error but redundant. Use <code>n = 10</code> with the same effect. </p>

<p>Then:</p>

<pre><code>while counter in range(0,m):
</code></pre>

<p>will always evaluate to <code>True</code>. <code>m</code> is *never modified so the membership test always succeeds, maybe you need to re-evaluate your looping.</p>

<pre><code>for x in range(1,y):
</code></pre>

<p>This will assign <code>x</code> the value <code>1</code> all the time. <code>y</code> evaluates to <code>2</code> by your arithmetic (int rounds floats to the floor, i.e <code>int(2.9) -&gt; 2</code>) so either use <code>math.ceil</code> or add one to your <code>y</code>.</p>

<p>Appart from that you re-assign variable names all the time inside your loops, that's confusing and might lead to unexpected behavior.</p>

python python-3.x for-loop increment