Skip to content
dreamcode
dreamcode
Back to map
While loops · Lesson 11 of 44
+15 XP on finish
PYTHON BASICS

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).

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.
main.py
PYTHON
real Python, runs in your browser
CONSOLE
- run your code to see output -