While loop that's meant to be infinite freezes after first cycle

Viewed 169

My goal is to make a program that prints onscreen all of the prime numbers it can find, however I have this issue where the while loop runs only once, instead of repeating forever.

def isPrime(num):
    if num < 2:
        return False
    if num == 2:
        return True
    if num % 2 == 0:
        return False
    i = 3
    while i * i <= num:
        if num % i == 0:
            return False
            i += 2

x = 1
while True:
    x += 1
    if isPrime(x):
        print (x)

I also have tried adding print("You can see this.") at the very end of the code, and it runs, but only once. I'm sure it's a common mistake, since Python is very strict on indentation, but could you guys help me discover it? Thanks in advance.

2 Answers
Related