Combining sequence, selection and iteration in one program
A complete program sets up variables first, repeats with a loop, uses an if inside the loop to make decisions, then prints the result after the loop ends.
Understanding Combining sequence, selection and iteration in one program in ACARA Digital Technologies Years 7–8
What it does: The variable is created and set to 0 on a line above the loop, so the loop can safely update it each time. The if runs on each pass of the loop, and console.log sits after the closing brace so it prints once, when the loop is done. The variable must exist before the loop uses it. The result is printed once the loop has finished. The if goes inside the loop so each number is checked. Selection inside iteration lets each repeat make a decision. Starting a counter at 0 gives you a number to add to. Without a starting value it is undefined, and undefined + 1 gives NaN.
Common mistakes: The counter must start at 0 before the loop. Starting at 1 makes the final count one too high. It should be let count = 0;. A total that changes inside the loop must be declared with let. A const cannot be reassigned, so total += i causes a TypeError. 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 635–666) and word search (Modules 635–695).
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
sequence, selection, iterationFill in the Blanks
Spot the Error
Student with a class code? Join your class →