← ACARA Digital Technologies Years 9–10

Counting items that meet a compound condition

Inside a loop, an IF with AND or OR tests each item and adds 1 to count only when the whole combined condition is true, so count ends as the number of items that qualify.

Understanding Counting items that meet a compound condition in ACARA Digital Technologies Years 9–10

What it does: NOT reverses the blank test, so count goes up only for items that have something in them. count starts at 0 before the loop, then the IF inside the loop adds 1 for each qualifying mark. AND needs both parts true. With OR, a mark like 120 or -5 would still be counted, because one part is true. One day cannot be both Saturday and Sunday, so AND is never true and count stays at 0. OR is true when either day matches. Starting at 0 means nothing has been counted yet. Starting at 1 makes the final total one too high.

Common mistakes: The counter must start at 0 before the loop. Starting at 1 makes the final count one too high. It should be count ← 0. Each Saturday (6) or Sunday (7) entry should add 1 to count, not take 1 away. The line 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 492–534) and word search (Modules 459–534).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line counts only marks from 50 to 100 inclusive?
IF mark >= 50 AND mark <= 100 THEN count ← count + 1IF mark >= 50 OR mark <= 100 THEN count ← count + 1
Matches
IF mark >= 50 OR mark <= 100 THEN count ← count + 1
↓
OR makes the test true for every mark, because any number is at least 50 or at most 100. It should be AND so only marks from 50 to 100 are counted.
Applying
Meanings
Term
IF mark >= 50 AND mark <= 100 THEN count ← count + 1
Meaning
Inside a loop, an IF with AND or OR tests each item and adds 1 to count only when the whole combined condition is true, so count ends as the number of items that qualify.
Practice
count ← 0
Testing
Gaps
IF mark >= 50 mark <= 100 THEN
Check Answer
Spots
1count ← 1
2FOR EACH m IN marks

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

The 'Peregrine Falcon' badge — Operator Ace, 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 counts only marks from 50 to 100 inclusive?
A. IF mark >= 50 OR mark <= 100 THEN count ← count + 1
B. IF mark >= 50 AND mark <= 100 THEN count ← count + 1 ✓
AND needs both parts true. With OR, a mark like 120 or -5 would still be counted, because one part is true.
2. The loop must count entries where day is Saturday or Sunday. Which condition is correct?
A. IF day = "Saturday" OR day = "Sunday" THEN ✓
B. IF day = "Saturday" AND day = "Sunday" THEN
One day cannot be both Saturday and Sunday, so AND is never true and count stays at 0. OR is true when either day matches.
3. Where should the line count ← count + 1 go to count qualifying items?
A. Inside the IF, so it only runs when the condition is true ✓
B. After ENDIF, so it runs for every item
If the add-1 line sits outside the IF, every item is counted. Inside the IF, only items that pass the test are counted.
4. What must happen to count before the loop starts?
A. count ← 1
B. count ← 0 ✓
Starting at 0 means nothing has been counted yet. Starting at 1 makes the final total one too high.
5. Which condition counts items that are NOT blank?
A. IF NOT (item = "") THEN count ← count + 1 ✓
B. IF item = "" THEN count ← count + 1
The second line counts the blank items instead. NOT flips the test so only items that are not blank are counted.

Match the Pairs

IF mark >= 50 AND mark <= 100 THEN count ← count + 1 → Adds 1 to count only when the mark is in the range 50 to 100, so both parts of the test must be true.
IF day = "Saturday" OR day = "Sunday" THEN count ← count + 1 → Adds 1 to count for each entry that falls on a weekend day, because only one of the two tests needs to be true.
Count only the items that are NOT blank by putting a NOT test inside the loop's IF. → IF NOT (item = "") THEN count ← count + 1
Set the counter to 0 before the loop starts so it begins with nothing counted. → count ← 0 FOR i ← 1 TO 10 IF mark >= 50 AND mark <= 100 THEN count ← count + 1 NEXT i
IF mark >= 50 OR mark <= 100 THEN count ← count + 1 → OR makes the test true for every mark, because any number is at least 50 or at most 100. It should be AND so only marks from 50 to 100 are counted.
FOR i ← 1 TO 10 count ← 0 IF day = "Saturday" OR day = "Sunday" THEN count ← count + 1 NEXT i → count is reset to 0 inside the loop on every pass, so the total is wiped each time. It must be set to 0 once before the loop.

Key Term

IF mark >= 50 AND mark <= 100 THEN count ← count + 1
Inside a loop, an IF with AND or OR tests each item and adds 1 to count only when the whole combined condition is true, so count ends as the number of items that qualify.

Fill in the Blanks

1. IF mark >= 50 AND mark <= 100 THEN count ← count + 1 ENDIF
Hint: Type the logical operator that makes the condition true only when both tests are true.
2. IF day = "Saturday" OR day = "Sunday" THEN count ← count + 1 ENDIF
Hint: Type the logical operator that makes the condition true when either weekend day matches.
3. IF NOT (item = "") THEN count ← count + 1 ENDIF
Hint: Type the logical operator that reverses the test, so only items that are not blank are counted.
4. IF mark >= 50 AND mark <= 100 THEN count ← count + 1 ENDIF
Hint: Type the amount added to the counter for each item that passes the combined test.
5. IF day = "Saturday" OR day = "Sunday" THEN count ← count + 1 ENDIF
Hint: Type the variable that the second half of the OR condition must test.

Spot the Error

Question 1
A count ← 1
B FOR EACH m IN marks
C IF m >= 50 AND m <= 100 THEN
D count ← count + 1
E ENDIF
F NEXT m
Line A — The counter must start at 0 before the loop. Starting at 1 makes the final count one too high. It should be count ← 0.
Question 2
A count ← 0
B FOR EACH day IN days
C IF day = 6 OR day = 7 THEN
D count ← count - 1
E ENDIF
F NEXT day
Line D — Each Saturday (6) or Sunday (7) entry should add 1 to count, not take 1 away. The line should be count ← count + 1.
Question 3
A count ← 0
B FOR EACH n IN names
C IF NOT (name = "") THEN
D count ← count + 1
E ENDIF
F NEXT name
Line B — The loop variable is n, but the IF tests name, which is never set. The loop should be FOR EACH name IN names.
Question 4
A count ← 0
B FOR EACH day IN days
C IF day = 6 AND day = 7 THEN
D count ← count + 1
E ENDIF
F NEXT day
Line C — A day cannot be both 6 and 7, so AND is never true and count stays 0. To count Saturday OR Sunday entries, use OR.
Question 5
A count ← 0
B FOR EACH m TO marks
C IF m >= 50 AND m <= 100 THEN
D count ← count + 1
E ENDIF
F NEXT m
Line B — A FOR EACH loop goes through a list using the keyword IN, not TO. It should be FOR EACH m IN marks.

Student with a class code? Join your class →