While Loops, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
While Loops in one minute
What students need to know
i starts at 0 and increments each loop. When i reaches 3, condition is False. while True runs forever — use break to exit when a condition is met.
True never becomes False — the loop continues indefinitely. The condition is checked first — 5>0 is True, so 5 prints before decrementing.
Mistakes students make
- Code inside the while loop must be indented.
- Missing colon at the end of the while line.
- Missing i = i + 1: the counter never increases, causing an infinite loop.
- while must be lowercase: While is not valid Python.
What students will learn in this module
Every question in Module 19
Quick questions
- When does a while loop stop?AAfter 10 timesBWhen the condition becomes False
- i=0\nwhile i<3:\n print(i)\n i=i+1\nWhat prints?A0, 1, 2B1, 2, 3
- What happens with while True: and no break?AThe loop runs foreverBIt runs once
- What does the condition in a while loop check?AWhether to keep loopingBHow many times to loop
- count=5\nwhile count>0:\n print(count)\n count=count-1\nWhat prints first?A0B5
Key terms
Students type the meaning of:
whileConditionInfinite loopCounter variable
Match the pairs
while x < 10
x += 1Match it to what it doesi = 0
while i < 5:
print(i)Match it to what it doesi = 0
while i < 3:
i += 1Match it to what it doeswhile True:
if done:
breakMatch it to what it doesi = 1
while i <= 3:
print(i)
i += 1Match it to what it doesx = 10
while x > 8:
x -= 1
print(x)Match it to what it doesFill in the blanks
i = 0 _____ i < 5: print(i) i = i + 1i = 0 while i < 5_ print(i) i = i + 1i = 0 while i _ 5: print(i) i = i + 1i = 0 while i < 5: print(i) i = i _ 1count = 3 while count _ 0: print(count) count = count - 1
Spot the error
Question 1
Ai = 0Bwhile i < 5:Cprint(i)Di = i + 1
Question 2
Ai = 0Bwhile i < 5C print(i)D i = i + 1
Question 3
Ai = 0Bwhile i < 5:C print(i)D # missing i = i + 1
Question 4
Ai = 0BWhile i < 5:C print(i)D i = i + 1
Question 5
Ai = 0Bwhile i < 5:C print(i)D i = i + 1E print('Done')
