← VCE Software Development U3O1

Counters and accumulators in pseudocode

A counter. It adds 1 to a variable each time a loop repeats. Set it to 0 before the loop. An accumulator works the same way: total <- total + x adds a value each time.

Understanding Counters and accumulators in pseudocode in VCE Software Development U3O1

What it does: The starting value count <- 0 comes before the loop, so the counter begins at zero and is not reset on each repeat. Putting the counter update inside an if block means it only increases when the item matches the condition. count <- count + 1 takes the old value and adds 1. count <- 1 just resets it to 1 every time. total <- total + mark adds each mark to the running total. total <- mark throws away the old total each time. The counter goes up by 1 on each of the 5 repeats: 1, 2, 3, 4, 5. It ends at 5.

Common mistakes: The running total must be set to 0 before the loop. Starting it at n adds an extra n to the answer. It should be total <- 0. This line replaces count with 1 each time instead of adding 1, so count never gets above 1. It should be count <- count + 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 48–71) and word search (Modules 10–71).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line sets up a counter correctly BEFORE a loop starts?
count <- count + 1count <- 0
Matches
for i from 1 to 10 count <- 0 count <- count + 1 end for
↓
count is set to 0 inside the loop, so it resets every repeat and always ends at 1. Move count <- 0 to before the loop.
Applying
Meanings
Term
count <- count + 1
Meaning
A counter. It adds 1 to a variable each time a loop repeats. Set it to 0 before the loop. An accumulator works the same way: total <- total + x adds a value each time.
Practice
total <- 0
Testing
Gaps
count <-
Check Answer
Spots
1input n
2total <- n

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

The 'Stag' badge — Forest Legend, 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 line sets up a counter correctly BEFORE a loop starts?
A. count <- 0 ✓
B. count <- count + 1
A counter must start at 0 before the loop. Then count <- count + 1 can add 1 on each repeat.
2. Which line adds 1 to a counter each time the loop repeats?
A. count <- count + 1 ✓
B. count <- 1
count <- count + 1 takes the old value and adds 1. count <- 1 just resets it to 1 every time.
3. An accumulator keeps a running total of marks. Which line does this inside the loop?
A. total <- mark
B. total <- total + mark ✓
total <- total + mark adds each mark to the running total. total <- mark throws away the old total each time.
4. True or false: you should set total <- 0 inside the loop so it starts fresh on every repeat.
A. False: set total <- 0 before the loop ✓
B. True: set total <- 0 inside the loop
If total is reset to 0 inside the loop, it forgets everything it added before. Set it to 0 once, before the loop.
5. You want to count how many scores are above 50. Which code does this?
A. count <- count + 1 then if score > 50
B. if score > 50 then count <- count + 1 ✓
Put the counter inside an if so it only goes up when the condition is true. This counts the matches.

Match the Pairs

count <- count + 1 → A counter: adds 1 to count each time the loop repeats
total <- total + score → An accumulator: adds the value of score to a running total each time the loop repeats
Set the counter to 0 before the loop so it starts from nothing → count <- 0 for i from 1 to 10 count <- count + 1 end for
Count only the matches: add 1 only when a condition is true → for i from 1 to 5 if mark >= 50 then passes <- passes + 1 end if end for
for i from 1 to 10 count <- 0 count <- count + 1 end for → count is set to 0 inside the loop, so it resets every repeat and always ends at 1. Move count <- 0 to before the loop.
total <- 0 for i from 1 to 5 total <- total + 1 end for → The accumulator adds 1 instead of the value being collected, so it only counts repeats. It should be total <- total + x.

Key Term

count <- count + 1
A counter. It adds 1 to a variable each time a loop repeats. Set it to 0 before the loop. An accumulator works the same way: total <- total + x adds a value each time.

Fill in the Blanks

1. count <- 0 for i from 1 to 10 count <- count + 1
Hint: Type the starting value a counter is set to before the loop begins
2. total <- 0 for i from 1 to 5 total <- total + i
Hint: Type the loop variable that is added to the running total each time
3. for i from 1 to 5 input score if score > 50 then count <- count + 1
Hint: Type the keyword that makes the counter only change for matches
4. total <- 0 for i from 1 to 4 total <- total + i
Hint: Type the arithmetic operator that adds to the accumulator
5. count <- 0 while count < 5 count <- count + 1
Hint: Type the variable name that the counter adds 1 to

Spot the Error

Question 1
A input n
B total <- n
C for i from 1 to n
D total <- total + i
E print total
Line B — The running total must be set to 0 before the loop. Starting it at n adds an extra n to the answer. It should be total <- 0.
Question 2
A count <- 0
B for i from 1 to 8
C input age
D count <- 1
E print count
Line D — This line replaces count with 1 each time instead of adding 1, so count never gets above 1. It should be count <- count + 1.
Question 3
A total <- 0
B for i from 1 to 5
C input price
D total <- total + 1
E print total
Line D — An accumulator adds the value from each repeat, not just 1. Adding 1 only counts the prices. It should be total <- total + price.
Question 4
A n <- 10
B counter <- 0
C for i from 1 to n
D count <- count + 1
E print count
Line B — The variable set to 0 is called counter, but the loop and print use count. The names must match. It should be count <- 0.
Question 5
A count <- 3
B for i from 1 to 6
C input mark
D if mark >= 50 then
E count <- count + 1
F print count
Line A — A counter must start at 0 before the loop. Starting at 3 makes the final count 3 too high. It should be count <- 0.

Student with a class code? Join your class →