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.
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
- Make sure something inside the loop changes the variable in the condition.
- Use Step through in Py-CRAFT to watch the variables and see why the loop never ends.
- For counting, a
forloop withrange()cannot run forever.