Choosing a for loop or a while loop (Python)
Use for when you know how many times to repeat, like 10 times. Use while when repeating depends on a condition that can change, like until the user types quit.
Understanding Choosing a for loop or a while loop (Python) in ACARA Digital Technologies Years 7–8
What it does: A fixed count of 5 is a perfect fit for for with range(5). lives starts at 0, so lives > 0 is False straight away and the loop body never runs. You don't know how many tries the user will need, so the loop depends on a condition. Use while.
Common mistakes: A for loop goes through a sequence such as range(10). It cannot take a condition. Either use 'while count < 10:' or write 'for count in range(10):'. The loop should keep going until the user types quit, so the condition must be text != 'quit'. With == the condition is False at the start, so the loop never runs.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 522–560) and word search (Modules 522–580).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
for vs whileFill in the Blanks
Spot the Error
Student with a class code? Join your class →