← ACARA Digital Technologies Years 5–6

Creating my own algorithm with branching, repetition and a counter

A finished algorithm joins steps, a decision (IF), a loop (REPEAT) and a counter to solve a school, game or recipe problem. You check it by following it step by step.

Understanding Creating my own algorithm with branching, repetition and a counter in ACARA Digital Technologies Years 5–6

What it does: The counter eggs goes up by 1 each time round the loop, so the loop stops when 3 eggs have been added. The IF decides which pencils to count, REPEAT goes through every pencil, and count keeps the total. A counter is a variable that changes by a set amount, like lives going down by 1. The IF is the decision. A counter that only counts some things needs an IF to choose which ones. IF ... THEN ADD 1 to count completes the idea. Combining sequence, branching, repetition and a counter lets one algorithm solve a bigger problem. Add SET count TO 0 before the REPEAT so the count starts at a known value.

Common mistakes: An IF decision needs the word THEN after its condition. Line 3 should be: IF bag is packed THEN. A set-number loop must say TIMES so we know it repeats a fixed number of times. Line 2 should be: REPEAT 3 TIMES.

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 120–132) and word search (Modules 106–132).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which algorithm uses a decision, a loop and a counter together to count how many pencils in a tray are sharp?
SET count TO 0. REPEAT for each pencil: IF it is sharp THEN ADD 1 to count. SAY count.SET count TO 0. REPEAT for each pencil: SAY pencil. SAY count.
Matches
REPEAT 10 TIMES IF homework done THEN ADD 1 TO count
↓
The counter was never set to 0 before the loop, so we do not know what number it starts from.
Applying
Meanings
Term
REPEAT + IF + count
Meaning
A finished algorithm joins steps, a decision (IF), a loop (REPEAT) and a counter to solve a school, game or recipe problem. You check it by following it step by step.
Practice
SET count TO 0
Testing
Gaps
SET count ←
Check Answer
Spots
2REPEAT 5 TIMES
3 IF bag is packed

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

The 'Wolverine' badge — Fearless Coder, 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 algorithm uses a decision, a loop and a counter together to count how many pencils in a tray are sharp?
A. SET count TO 0. REPEAT for each pencil: IF it is sharp THEN ADD 1 to count. SAY count. ✓
B. SET count TO 0. REPEAT for each pencil: SAY pencil. SAY count.
The IF decides which pencils to count, REPEAT goes through every pencil, and count keeps the total.
2. A game algorithm gives the player 3 lives. Which part is the counter?
A. SET lives TO 3, then SUBTRACT 1 each time the player is hit ✓
B. IF the player is hit THEN play a sound
A counter is a variable that changes by a set amount, like lives going down by 1. The IF is the decision.
3. Which recipe algorithm repeats a step the right number of times?
A. SET eggs TO 0. REPEAT UNTIL eggs = 3: ADD 1 egg to the bowl, ADD 1 to eggs. ✓
B. SET eggs TO 0. ADD 1 egg to the bowl. ADD 1 to eggs. STOP.
The REPEAT UNTIL loop and the counter work together, so exactly 3 eggs go in the bowl.
4. Your classroom algorithm should count students who brought a hat. Where does the IF go?
A. After the REPEAT, so it checks only the last student
B. Inside the REPEAT, so it checks every student ✓
When the IF is inside the loop, each student gets checked and the counter only goes up for those with a hat.
5. You wrote an algorithm to count red cards. What is the best way to check that it works?
A. Read the title and decide it looks right
B. Follow it step by step with a small set of cards and track the count ✓
Following the steps one at a time, and writing down the counter each time, shows if the algorithm is correct.

Match the Pairs

SET count TO 0 REPEAT 5 TIMES IF page is torn THEN ADD 1 TO count → A school routine that checks 5 library books and counts how many pages are torn
SET lives TO 3 REPEAT UNTIL lives = 0 IF hit THEN TAKE 1 FROM lives → A game that keeps going until the player has lost all 3 lives
A recipe algorithm that adds eggs one at a time, counts them and stops at 3 → SET eggs TO 0 REPEAT UNTIL eggs = 3 ADD 1 egg ADD 1 TO eggs
Checking your algorithm by following it step by step with a small starting value → count = 0, round 1: IF true THEN count = 1, round 2: IF false THEN count stays 1
REPEAT 10 TIMES IF homework done THEN ADD 1 TO count → The counter was never set to 0 before the loop, so we do not know what number it starts from.
SET score TO 0 REPEAT UNTIL score = 10 IF answer correct THEN ADD 1 TO score → If the answer is wrong, score never changes, so the loop could never stop. The counter must go up each round, or the loop needs a way to end.

Key Term

REPEAT + IF + count
A finished algorithm joins steps, a decision (IF), a loop (REPEAT) and a counter to solve a school, game or recipe problem. You check it by following it step by step.

Fill in the Blanks

1. SET count ← 0 REPEAT 5 TIMES IF bag has book THEN ADD 1 to count
Hint: Type the number the counter starts on before any books have been checked.
2. SET lives ← 3 REPEAT UNTIL lives = 0 IF hit THEN SET lives ← lives - 1
Hint: Type the loop keyword that keeps the game repeating until the condition becomes true.
3. SET eggs ← 0 REPEAT 3 TIMES IF egg is fresh THEN ADD 1 to eggs
Hint: Type the keyword that starts a decision inside the loop.
4. SET stirs ← 0 REPEAT UNTIL stirs = 10 SET stirs ← stirs + 1
Hint: Type the operator that makes the counter grow by one each time the loop runs.
5. SET count ← 0 REPEAT 3 TIMES ADD 1 TO count SAY count
Hint: After following the loop step by step, type the name of the variable that holds the total to show.

Spot the Error

Question 1
A SET ready TO 0
B REPEAT 5 TIMES
C IF bag is packed
D ADD 1 TO ready
E END IF
F END REPEAT
Line C — An IF decision needs the word THEN after its condition. Line 3 should be: IF bag is packed THEN.
Question 2
A SET stars TO 0
B REPEAT 3
C IF card is a star THEN
D ADD 1 TO stars
E END IF
F END REPEAT
Line B — A set-number loop must say TIMES so we know it repeats a fixed number of times. Line 2 should be: REPEAT 3 TIMES.
Question 3
A SET stirs TO 0
B REPEAT UNTIL stirs = 10
C STIR the mixture
D SET stirs TO 1
E END REPEAT
Line D — Setting stirs to 1 each time means the counter never goes up past 1, so the loop never stops. Line 4 should be: ADD 1 TO stirs.
Question 4
A SET cracked TO 6
B REPEAT 6 TIMES
C IF egg is cracked THEN
D ADD 1 TO cracked
E END IF
F END REPEAT
Line A — A counter must start at 0 before we begin counting. Starting at 6 gives the wrong total. Line 1 should be: SET cracked TO 0.
Question 5
A SET late TO 0
B REPEAT 5 TIMES
C IF student is late THEN
D ADD 1 TO days
E END IF
F END REPEAT
Line D — The counter being used is late, so we must add 1 to late. Adding to a different variable leaves late unchanged. Line 4 should be: ADD 1 TO late.

Student with a class code? Join your class →