← IGCSE Computer Science Paper 2

Counting in a loop (7a)

A counter is a variable set to 0 before a loop, then increased by 1 with Counter ← Counter + 1 each time the thing being counted happens.

Understanding Counting in a loop (7a) in IGCSE Computer Science Paper 2

What it does: The counter only increases when the IF condition is true, so only the marks being counted are added to the count. Initialise the counter once before the loop. If it is set to 0 inside the loop, it resets every time and the count is lost. The variable being changed goes on the left of the arrow. The new value, Count + 1, goes on the right. A counter adds 1 for each event. Adding the entered values is called totalling, not counting. Count starts at 0 and goes up by 1 on each of the 5 repeats, so it ends at 5.

Common mistakes: A counter goes up by 1 each time, so it needs Counter ← Counter + 1. Subtracting 1 makes the counter go down instead of counting. A counter must be set to 0 before the loop starts. Starting at 1 makes the final count one too high. It should be Counter ← 0.

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 47–57) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Where should a counter be set to 0?
Inside the loop, at the start of each repeatBefore the loop starts
Matches
FOR Index ← 1 TO 10 Counter ← 0 INPUT Number IF Number > 5 THEN Counter ← Counter + 1 ENDIF NEXT Index
↓
Counter ← 0 is inside the loop, so the counter resets to zero on every repeat and the count is lost. It must be set before the loop starts.
Applying
Meanings
Term
Counter ← Counter + 1
Meaning
A counter is a variable set to 0 before a loop, then increased by 1 with Counter ← Counter + 1 each time the thing being counted happens.
Practice
Counter ← 0
Testing
Gaps
Counter ←
Check Answer
Spots
2FOR Index ← 1 TO 5
3 Counter ← Counter - 1

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

The 'Gulper Eel' badge — Deep Streak, 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. Where should a counter be set to 0?
A. Inside the loop, at the start of each repeat
B. Before the loop starts ✓
Initialise the counter once before the loop. If it is set to 0 inside the loop, it resets every time and the count is lost.
2. Which line adds 1 to a counter called Count?
A. Count ← Count + 1 ✓
B. Count + 1 ← Count
The variable being changed goes on the left of the arrow. The new value, Count + 1, goes on the right.
3. A program counts how many marks entered are 50 or more. Where does the counting line go?
A. Outside the IF, so it runs for every mark
B. Inside an IF Mark >= 50 THEN ✓
To count only when something is true, put Counter ← Counter + 1 inside the IF. Otherwise it counts every entry.
4. A counter is never set to 0 before the loop. What is the problem?
A. It starts with an unknown value, so the final count may be wrong ✓
B. The loop will run one extra time
Without initialising, the counter has no reliable starting value. Always write Counter ← 0 before the loop.
5. Which statement about a counter is true?
A. It goes up by 1 each time the thing being counted happens ✓
B. It adds the value the user typed in each time
A counter adds 1 for each event. Adding the entered values is called totalling, not counting.

Match the Pairs

Counter ← 0 → Initialises the counter to zero before the loop starts, so counting begins from nothing
Counter ← Counter + 1 → Adds 1 to the counter each time it runs, so the counter goes up by one
Count only the marks that are 50 or more by putting the increase inside an IF that is true only for those marks → IF Mark >= 50 THEN Passes ← Passes + 1 ENDIF
Count only the valid entries by increasing the counter after a check shows the input is within the allowed range → IF Age >= 11 AND Age <= 16 THEN ValidCount ← ValidCount + 1 ENDIF
FOR Index ← 1 TO 10 Counter ← 0 INPUT Number IF Number > 5 THEN Counter ← Counter + 1 ENDIF NEXT Index → Counter ← 0 is inside the loop, so the counter resets to zero on every repeat and the count is lost. It must be set before the loop starts.
Counter ← 0 FOR Index ← 1 TO 10 INPUT Number Counter ← Counter + 1 IF Number > 5 THEN OUTPUT Number ENDIF NEXT Index → Counter ← Counter + 1 is outside the IF, so it counts every number entered, not only the numbers greater than 5.

Key Term

Counter ← Counter + 1
A counter is a variable set to 0 before a loop, then increased by 1 with Counter ← Counter + 1 each time the thing being counted happens.

Fill in the Blanks

1. Counter ← 0 FOR Index ← 1 TO 10 INPUT Num
Hint: Type the starting value a counter is given before the loop begins.
2. IF Mark >= 50 THEN Passes ← Passes + 1 ENDIF
Hint: Type the arithmetic operator that makes the counter go up each time.
3. IF Score > 90 THEN Top ← Top + 1 ENDIF
Hint: Type the counter variable whose current value is being increased.
4. IF Age >= 18 THEN Adults ← Adults + 1 ENDIF
Hint: Type the keyword that makes the counter increase only when the condition is true.
5. IF Num >= 1 AND Num <= 10 THEN Valid ← Valid + 1 ENDIF
Hint: Type the logical operator that joins both range tests so only valid entries are counted.

Spot the Error

Question 1
A Counter ← 0
B FOR Index ← 1 TO 5
C Counter ← Counter - 1
D NEXT Index
E OUTPUT Counter
Line C — A counter goes up by 1 each time, so it needs Counter ← Counter + 1. Subtracting 1 makes the counter go down instead of counting.
Question 2
A DECLARE Counter : INTEGER
B Counter ← 1
C FOR Index ← 1 TO 10
D Counter ← Counter + 1
E NEXT Index
F OUTPUT Counter
Line B — A counter must be set to 0 before the loop starts. Starting at 1 makes the final count one too high. It should be Counter ← 0.
Question 3
A Count ← 0
B INPUT Score
C WHILE Score <> -1 DO
D Counter ← Counter + 1
E INPUT Score
F ENDWHILE
Line A — The variable initialised must have the same name as the counter used in the loop. Count is a different variable from Counter, so Counter is never set to 0. It should be Counter ← 0.
Question 4
A Counter ← 0
B FOR Index ← 1 TO 20
C IF Index MOD 2 ← 0 THEN
D Counter ← Counter + 1
E ENDIF
F NEXT Index
Line C — A condition compares values, so it must use the relational operator = and not the assignment arrow ←. It should be IF Index MOD 2 = 0 THEN.
Question 5
A DECLARE Attempts : INTEGER
B Attempts = 0
C REPEAT
D INPUT Age
E Attempts ← Attempts + 1
F UNTIL Age >= 0 AND Age <= 120
Line B — Setting the starting value of the counter needs the assignment arrow, not the comparison =. With = the counter is never given the value 0. It should be Attempts ← 0.

Student with a class code? Join your class →