PYTHON BASICSChapter 3 · Loops and iteration
Looping while true
A while loop keeps running as long as a condition remains True. You must make sure the condition eventually becomes False, or your loop will run forever (an infinite loop).
Worked example
How it reads
- while stars > 0: checks the condition before each turn
- stars = stars - 1 decreases the counter so the loop eventually stops

Cloud tip: Always modify the variable in your condition inside the loop body, otherwise you will get stuck in an infinite loop.


