← ACARA Digital Technologies Years 7–8

Infinite loops and how to stop them

A while loop whose condition never becomes False, often because the loop variable is never updated. Stop it with the Stop button, or fix it by changing the variable inside the loop.

Understanding Infinite loops and how to stop them in ACARA Digital Technologies Years 7–8

What it does: When the if condition is True, break jumps out of the loop immediately, so the loop stops even though while True never becomes False. An infinite loop will never finish on its own. The Stop button ends the running program. break leaves the loop straight away. Printing a value does not stop the loop. Changing the variable is not enough. It must change in a direction that makes the condition False. Use x = x - 1 to count down. Forgetting to update the loop variable is the most common cause of an infinite loop.

Common mistakes: count goes down, so count <= 5 is always True and the loop never ends. It should be count = count + 1 so count grows towards 5. A while line must end with a colon. It should be while True: and the break inside is what stops this loop.

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

Learning
Duo
Which loop is an infinite loop?
count = 1 while count <= 5: print(count)count = 1 while count <= 5: print(count) count = count + 1
Matches
count = 0 while count < 5: print(count)
↓
count never changes inside the loop, so count < 5 stays True forever. Add count = count + 1 inside the loop.
Applying
Meanings
Term
infinite loop
Meaning
A while loop whose condition never becomes False, often because the loop variable is never updated. Stop it with the Stop button, or fix it by changing the variable inside the loop.
Practice
count = 1
Testing
Gaps
= count + 1
Check Answer
Spots
2while count <= 5:
3 count = count - 1

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

The 'Snow Leopard' badge — Silent Debugger, 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. Which loop is an infinite loop?
A. count = 1 while count <= 5: print(count) ✓
B. count = 1 while count <= 5: print(count) count = count + 1
The first loop never changes count, so count <= 5 stays True forever. The second loop adds 1 each time, so it stops.
2. Why does this loop never stop? while True: print('Hi')
A. The print() function is written wrongly
B. The condition is always True and can never be False ✓
while True: has a condition that never becomes False, so the loop runs forever unless you add break or press Stop.
3. Your program is stuck in an infinite loop and keeps printing. What should you do first?
A. Click the Stop button ✓
B. Wait for it to finish by itself
An infinite loop will never finish on its own. The Stop button ends the running program.
4. What is the best fix for a loop that forgot to update its variable?
A. Add count = 1 before the loop
B. Add count = count + 1 inside the loop ✓
The variable must change inside the loop so the condition can become False. Setting it once before the loop does not help.
5. Which line placed inside a while True: loop gives it a way to exit?
A. if count == 5: break ✓
B. if count == 5: print(count)
break leaves the loop straight away. Printing a value does not stop the loop.

Match the Pairs

while True: print("Hi") → A condition that can never be False, so this loop runs forever unless you use break or press Stop
count = count + 1 → Updates the loop variable each time round so the while condition can eventually become False
Adding break inside the loop is one way to exit a loop that would otherwise run forever → while True: if count == 5: break
A loop with an updated variable ends because its condition finally becomes False → while count < 3: count = count + 1
count = 0 while count < 5: print(count) → count never changes inside the loop, so count < 5 stays True forever. Add count = count + 1 inside the loop.
count = 10 while count > 0: count = count + 1 → count moves away from 0, so count > 0 can never become False. Change it to count = count - 1.

Key Term

infinite loop
A while loop whose condition never becomes False, often because the loop variable is never updated. Stop it with the Stop button, or fix it by changing the variable inside the loop.

Fill in the Blanks

1. count = 0 while count < 3: count = count + 1
Hint: Type the loop variable that must be updated inside the loop so the condition can become False.
2. while True: if input("Quit? ") == "y": break
Hint: Type the keyword that exits a loop straight away.
3. while True: print("Hello")
Hint: Type the Boolean value that makes the condition never become False, so the loop never ends.
4. count = 10 while count > 0: count = count - 1
Hint: Type the arithmetic operator that moves count towards making the condition False.
5. count = 0 while count < 3: count = count + 1
Hint: Type the keyword that starts a loop that repeats as long as its condition is True.

Spot the Error

Question 1
A count = 1
B while count <= 5:
C count = count - 1
D print(count)
Line C — count goes down, so count <= 5 is always True and the loop never ends. It should be count = count + 1 so count grows towards 5.
Question 2
A while True
B word = input("Word: ")
C if word == "quit":
D break
Line A — A while line must end with a colon. It should be while True: and the break inside is what stops this loop.
Question 3
A count = 1
B while count > 0:
C print(count)
D count = count + 1
Line B — count starts at 1 and only goes up, so count > 0 can never be False and the loop runs forever. It should be while count < 5:.
Question 4
A count = 0
B while count < 3:
C counter = count + 1
D print("Hi")
Line C — This updates a different variable called counter, so count never changes and the loop never ends. It should be count = count + 1.
Question 5
A while True:
B answer = input("Quit? ")
C if answer == "yes":
D continue
Line D — continue jumps back to the top of the loop instead of leaving it, so the loop never stops. It should be break to exit the loop.

Student with a class code? Join your class →