I'm having a really weird problem. I have a loop where I use a variable, i, as a loop counter, and the loop stops when n > i is no longer true. However, when I run it, it doesn't stop. What am I doing wrong? Here's the offending code. Code: def returnPrimes(n): # Returns all the primes from 2 to n. i = 2 # Loop counter primeset = [] # Set of primes generated so far while n > i: print "Checking", i if isPrime(i, primeset): print i, "is prime!" primeset.append(i) raw_input("Press enter to continue.") i += 1 return primeset Thanks. EDIT: Okay, I've changed it so it uses a for loop - for i in range(2,n): - and that's worked but I'm still curious about what I did wrong with the while loop. EDIT: Tried the original code again, and it started working. So, not really sure what went wrong there. Oh well.
What does the standard output look like? The code looks fine but that line of i += 1 looks like it's having no effect, is the indendation correct?