Write Python. Understand every error.

Open the editor

Error guide · Other errors

My program never stops: endless loops

The program kept running without finishing, so Py-CRAFT stopped it after a few seconds.

Example

n = 1
while n < 5:
    print(n)

What happens

The program never finishes. Py-CRAFT stops it after a few seconds, or as soon as it has printed too much output, and shows which line was running.

Try this code in Py-CRAFT

Why it happens

A while loop repeats as long as its condition is True. If nothing inside the loop changes the condition, it never becomes False, and the loop runs forever.

How to fix it

n = 1
while n < 5:
    print(n)
    n += 1

Output: 1 ⏎ 2 ⏎ 3 ⏎ 4

Tips

Learn the ideas behind it

Other common errors

Share this page: