Step 1 of 6

Step 1 · Read and run

While it's True

A while loop is like an if that keeps coming back. Python checks the comparison; if it's True, it runs the indented lines, then goes back to the top and checks again. When the comparison is False, the loop ends.

A for loop counts for you. A while loop doesn't, so here the program makes its own counter and adds 1 to it each time round.

Press Step through to watch Python check count <= 5 each time.

Run the program to carry on.
count.py

Output

Press Run to see what your program prints.