break and continue, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
break and continue in one minute
What students need to know
break exits the loop immediately when the condition is met. continue skips printing when i==2 but the loop continues for other values.
continue skips the rest of this iteration and jumps to the next one. break only makes sense inside a loop — Python raises SyntaxError otherwise.
Mistakes students make
- break must be INSIDE a loop: it can't be used outside.
- break must be lowercase Break is not valid Python.
- continue must be lowercase Continue is not valid Python.
- break must be indented inside the if block.
PREVIOUS · MODULE 22Error Handling – try/except basics
YOU ARE HERE · MODULE 23break and continue
NEXT · MODULE 24Functions – Defining
What students will learn in this module
Every question in Module 23
Quick questions
- What does break do?ASkips to next iterationBExits the loop immediately
- What does continue do?ASkips to the next iterationBExits the loop
- for i in range(5):\n if i == 3:\n break\n print(i)\nWhat prints?A0, 1, 2, 3B0, 1, 2
- for i in range(5):\n if i == 3:\n continue\n print(i)\nWhat prints?A0, 1, 2, 4B0, 1, 2
- Can you use break outside a loop?ANo causes SyntaxErrorBYes
Key terms
Students type the meaning of:
breakcontinuewhile True: + breakLoop control
Match the pairs
breakMatch it to what it doesfor i in range(5):
continue
print(i)Match it to what it doesfor i in range(5):
if i == 3:
breakMatch it to what it doesfor i in range(5):
if i == 2:
continue
print(i)Match it to what it doesfor i in range(5):
if i == 3:
break
print(i)Match it to what it doesfor i in range(4):
if i == 2:
continue
print(i)Match it to what it doesFill in the blanks
for i in range(10): if i == 5: _____ print(i)for i in range(10): if i == 3: ________ print(i)while True: x = input('Enter: ') if x == 'quit': _____for i in range(10): if i % 2 __ 0: continue print(i)for i in range(20): if i __ 10: break print(i)
Spot the error
Question 1
AbreakBfor i in range(5):C print(i)Dprint('Done')
Question 2
Afor i in range(10):B if i == 5:C BreakD print(i)
Question 3
Afor i in range(10):B if i == 5:C ContinueD print(i)
Question 4
Afor i in range(10):B if i == 5:C breakD print(i)
Question 5
Afor i in range(10):B if i == 5:C break()D print(i)
