← Years 7–8 Creating Digital Solutions

break to exit a loop

A keyword that stops the loop it is in straight away. The program then carries on with the first line after the loop. It is often used inside while True to exit when a condition is met.

Understanding break to exit a loop in Years 7–8 Creating Digital Solutions

What it does: An if statement checks the condition, and break inside it ends the loop as soon as the condition is met. break leaves the loop at once, so the program continues with the print() line, which is outside the loop. break jumps out of the loop. It does not go back to the top of the loop. break is inside the if block, so it must be indented. Without indentation Python gives an IndentationError. Python only understands break. Spelling it brake would cause a NameError.

Common mistakes: True must start with a capital letter in Python. Lowercase true is not a keyword, so Python gives a NameError. It should be while True:. The while line is missing a colon at the end. Python needs the colon before the indented loop body. It should be while True:.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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 50–125) and word search (Modules 3–125).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does the break keyword do inside a loop?
It pauses the loop for one secondIt stops the loop straight away
Matches
while True: name = input('Name: ') print(name)
↓
There is no break, so the loop never ends and the program runs forever. Add an if statement with break inside the loop.
Applying
Meanings
Term
break
Meaning
A keyword that stops the loop it is in straight away. The program then carries on with the first line after the loop. It is often used inside while True to exit when a condition is met.
Practice
while True:
Testing
Gaps
Check Answer
Spots
1score = 0
2while true:

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Chameleon' badge — Type Shifter, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does the break keyword do inside a loop?
A. It pauses the loop for one second
B. It stops the loop straight away ✓
break ends the loop immediately. The program then carries on with the first line after the loop.
2. Which loop runs forever unless something inside it uses break?
A. while True: ✓
B. for i in range(3):
The condition True is always true, so the loop never ends by itself. A break inside the loop is how you get out.
3. After break runs, which line does Python run next?
A. The first line after the loop ✓
B. The first line inside the loop again
break jumps out of the loop. It does not go back to the top of the loop.
4. Which code uses break correctly?
A. if guess == 7: break ✓
B. if guess == 7: break
break is inside the if block, so it must be indented. Without indentation Python gives an IndentationError.
5. A student writes this loop: while True: print("Hi") What happens?
A. It prints Hi once and then stops
B. It prints Hi forever because there is no break ✓
With no break (or other way out), a while True loop never ends. You would have to stop the program yourself.

Match the Pairs

break → Stops the loop it is in straight away and jumps to the first line after the loop
while True: → Starts a loop that keeps running forever until a break is reached
Exit a loop when the user types 'quit' → if answer == 'quit': break
The line after the loop runs once break has ended the loop → while True: break print('Done')
while True: name = input('Name: ') print(name) → There is no break, so the loop never ends and the program runs forever. Add an if statement with break inside the loop.
while True: age = int(input('Age: ')) break → The break is not indented, so it is outside the loop and cannot end it. It must be indented inside the loop, usually under an if.

Key Term

break
A keyword that stops the loop it is in straight away. The program then carries on with the first line after the loop. It is often used inside while True to exit when a condition is met.

Fill in the Blanks

1. while True: if input("Quit? ") == "y": break
Hint: Type the keyword that stops the loop straight away.
2. while True: if input("Quit? ") == "y": break
Hint: Type the Boolean value that keeps the loop running until break is used.
3. while True: if input("Quit? ") == "y": break
Hint: Type the keyword that checks a condition before break runs.
4. while True: if int(input("Guess: ")) == 7: break
Hint: Type the comparison operator that checks if two values are equal.
5. while True: if input("Quit? ") == "y": break
Hint: Type the keyword that starts a loop which repeats while its condition is true.

Spot the Error

Question 1
A score = 0
B while true:
C score += 2
D if score >= 10:
E break
F print(score)
Line B — True must start with a capital letter in Python. Lowercase true is not a keyword, so Python gives a NameError. It should be while True:
Question 2
A while True
B pw = input('Password: ')
C if pw == 'cat':
D break
E print('Welcome')
Line A — The while line is missing a colon at the end. Python needs the colon before the indented loop body. It should be while True:
Question 3
A while True:
B n = int(input('Number: '))
C if n = 0:
D break
E print('Done')
Line C — A single = assigns a value. An if condition needs == to compare. It should be if n == 0: so the loop can break when the number is 0.
Question 4
A while True:
B cmd = input('Go? ')
C if cmd == 'stop':
D brake
E print('Stopped')
Line D — The keyword is spelled break, not brake. Python does not know brake, so the loop would not exit. It should be break.
Question 5
A while True:
B age = int(input('Age: '))
C if age > 0
D break
E print('Thanks')
Line C — The if line is missing its colon. Python needs a colon at the end of the line before the indented break. It should be if age > 0:

Student with a class code? Join your class →