Totals and counters in a loop
Adds each value to a running total inside a loop. Start with let total = 0 before the loop, and use count++ to count how many times something happens. Print the results after the loop.
Understanding Totals and counters in a loop in ACARA Digital Technologies Years 7–8
What it does: total += i adds the current loop value onto the total on every pass through the loop. Printing after the closing brace of the loop shows only the final answer, not every step along the way. count++ adds 1 to count each time it runs. count = 1 just sets it to 1 again and again. Total and count change as the loop runs, so they need let. A const variable cannot be reassigned and gives a TypeError. count goes up by 1 on each of the 5 repeats: 0, 1, 2, 3, 4, 5. It ends at 5. count++ is shorthand for count = count + 1 and is used inside a loop to count events.
Common mistakes: i-- makes the counter go down, so i <= 5 is always true and the loop never ends. It should be i++ so the loop counts up and finishes. A total must start at 0 before the loop. Starting at 1 makes the final answer 1 too big. It should be let total = 0;.
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 599–610) and word search (Modules 583–613).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
total += value;Fill in the Blanks
Spot the Error
Student with a class code? Join your class →