Paul's Python CoursePPC

Loops that never end

Not met yet

A loop whose test never becomes False goes round forever. Usually a line that should change the variable in the test is missing, or the test can be stepped over, like != 0 on a count that goes 3, 1, -1. Press Stop to get out, then check that every pass moves the loop closer to its end.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks the variable in a while test changes by itself, without a line in the body that changes it.
  • Thinks while n != 0 stops once n goes past zero, even if it never equals zero exactly.

Where it comes up