← Years 5–6 Creating Digital Solutions

Using a variable as a counter in a loop

A counter is a variable that goes up by 1 each time a loop repeats, so it counts how many times something happened. Set it to 0 before the loop starts.

Understanding Using a variable as a counter in a loop in Years 5–6 Creating Digital Solutions

What it does: The loop keeps going until the counter equals 5, so the counter decides when the loop stops. Adding 1 each time the loop repeats makes the counter go up. Setting it to 0 inside the loop would wipe out the count every time. A counter does not change the speed of the loop. It just remembers how many times something has happened.

Common mistakes: The counter starts at 0, so 'counter = 0' is already true and the loop never runs. The loop should stop when the counter reaches the target number, so it should be REPEAT UNTIL counter = 5. Subtracting 1 makes the counter go down (-1, -2, ...), so it never reaches 3 and the loop never stops. A counter goes up by 1 each time, so it should be counter ← counter + 1.

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 61–74) and word search (Modules 41–74).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A student wants to count how many times a loop repeats. Which line goes inside the loop?
counter ← counter + 1counter ← 0
Matches
REPEAT UNTIL counter = 4 counter ← 0
↓
The counter is set to 0 inside the loop, so it never goes up and the loop never stops. It should be counter ← counter + 1.
Applying
Meanings
Term
counter ← counter + 1
Meaning
A counter is a variable that goes up by 1 each time a loop repeats, so it counts how many times something happened. Set it to 0 before the loop starts.
Practice
counter ← 0
Testing
Gaps
counter ←
Check Answer
Spots
1counter ← 0
2REPEAT UNTIL counter = 0

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

The 'Ermine' badge — Tundra Streak, 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. A student wants to count how many times a loop repeats. Which line goes inside the loop?
A. counter ← counter + 1 ✓
B. counter ← 0
Adding 1 each time the loop repeats makes the counter go up. Setting it to 0 inside the loop would wipe out the count every time.
2. Where should you set a counter to 0?
A. Before the loop starts ✓
B. Inside the loop at the end
Reset the counter to 0 before the loop so you start counting from zero. If you reset it inside the loop, it never builds up.
3. A counter starts at 0. The loop repeats 4 times and adds 1 each time. What is the counter after the loop?
A. 5
B. 4 ✓
0 → 1 → 2 → 3 → 4. The counter goes up by 1 on each of the 4 repeats, so it ends at 4.
4. What does a counter variable do in a loop?
A. It keeps track of how many times something has happened ✓
B. It makes the loop run faster
A counter does not change the speed of the loop. It just remembers how many times something has happened.
5. Which loop stops when the counter reaches 10?
A. REPEAT counter TIMES UNTIL 0
B. REPEAT UNTIL counter = 10 ✓
REPEAT UNTIL checks a condition each time. When counter = 10 is true, the loop stops.

Match the Pairs

counter ← 0 → Sets the counter to 0 before the loop starts so counting begins from zero
counter ← counter + 1 → Adds 1 to the counter each time the loop repeats, so it counts how many times something happened
Stop the loop when the counter reaches 5 → REPEAT UNTIL counter = 5
Start counting from zero before the loop begins → counter ← 0 REPEAT UNTIL counter = 3 counter ← counter + 1
REPEAT UNTIL counter = 4 counter ← 0 → The counter is set to 0 inside the loop, so it never goes up and the loop never stops. It should be counter ← counter + 1.
REPEAT UNTIL counter = 3 counter ← counter + 1 → The counter was never set to 0 before the loop. Add counter ← 0 before the loop so it starts from a known number.

Key Term

counter ← counter + 1
A counter is a variable that goes up by 1 each time a loop repeats, so it counts how many times something happened. Set it to 0 before the loop starts.

Fill in the Blanks

1. counter ← 0 REPEAT UNTIL counter = 5 counter ← counter + 1
Hint: Type the number the counter starts at before the loop begins
2. claps ← 0 REPEAT UNTIL claps = 10 claps ← claps + 1
Hint: Type the operator that makes the counter go up
3. counter ← 0 REPEAT UNTIL counter = 5 counter ← counter + 1
Hint: Type the comparison symbol that checks if the counter has reached the target
4. jumps ← 0 REPEAT UNTIL jumps = 8 jumps ← jumps + 1
Hint: Type the keyword that repeats the loop up to the moment the condition becomes true
5. counter ← 0 REPEAT UNTIL counter = 5 counter ← counter + 1
Hint: Type the amount the counter goes up by each time the loop repeats

Spot the Error

Question 1
A counter ← 0
B REPEAT UNTIL counter = 0
C SAY 'Hello'
D counter ← counter + 1
E END REPEAT
Line B — The counter starts at 0, so 'counter = 0' is already true and the loop never runs. The loop should stop when the counter reaches the target number, so it should be REPEAT UNTIL counter = 5.
Question 2
A counter ← 0
B REPEAT UNTIL counter = 3
C counter ← counter - 1
D SAY counter
E END REPEAT
Line C — Subtracting 1 makes the counter go down (-1, -2, ...), so it never reaches 3 and the loop never stops. A counter goes up by 1 each time, so it should be counter ← counter + 1.
Question 3
A counter ← 0
B REPEAT 10 TIMES
C counter ← 1
D END REPEAT
E SAY counter
Line C — Setting the counter to 1 inside the loop wipes out the count every time, so it stays at 1. It should add 1 to the old value: counter ← counter + 1.
Question 4
A WHEN green flag clicked
B counter ← 5
C REPEAT 5 TIMES
D counter ← counter + 1
E SAY counter
Line B — A counter must be reset to 0 before the loop starts. Starting at 5 would make the final count 10, not 5. It should be counter ← 0.
Question 5
A counter ← 0
B REPEAT UNTIL counter = 4
C SAY 'Jump!'
D counter = counter + 1
E END REPEAT
Line D — The = sign compares two values; it does not change the variable. The counter never goes up, so the loop never ends. Use the assignment arrow: counter ← counter + 1.

Student with a class code? Join your class →