Counting only some things with IF inside a loop
Inside a loop, the IF checks each item. Only when the item meets the condition does the counter go up by 1. If the condition is false, the counter stays the same.
Understanding Counting only some things with IF inside a loop in ACARA Digital Technologies Years 5–6
What it does: A black card does not meet card = red, so the step after THEN is skipped and count does not change. The counter starts at 0 before the loop. The IF inside the loop adds 1 only for red cards. The condition is false because the card is blue. The counter stays the same. There are 3 red cards. The two blue cards do not meet the condition, so they are not counted. The IF must be inside the loop. Then every answer gets checked one at a time. The loop repeats for every item, but the IF decides whether the counter goes up.
Common mistakes: The counter must start at 0 before any cards are checked. Starting at 1 means the final count is always one too high. It should be count ← 0. The loop needs to go through every answer in the quiz, not through the score. It should be FOR EACH answer IN quiz.
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 106–119) 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.
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
IF card = red THEN count ← count + 1Fill in the Blanks
Spot the Error
Student with a class code? Join your class →