← IGCSE Computer Science Paper 2

Counting in a loop (8.1b)

Adds 1 to the counter each time the thing being counted happens. Set Count <- 0 before the loop, and put this inside the loop (inside an IF to count only some values).

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

What it does: The IF means Count only goes up when the condition is true, so only values that meet the condition are counted. The counter must be set to 0 once, before the loop. If it were inside the loop, it would reset to 0 on every repeat and you would lose the count. The variable being changed goes on the left of the arrow. Count <- Count + 1 takes the old value, adds 1 and stores it back in Count. The counting line must be between THEN and ENDIF so the condition controls it. In the wrong answer the IF is empty, so every value is counted.

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. Count = 0 is a comparison, not an assignment. To set the counter to 0 you must write Count <- 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 379–388) and word search (Modules 379–398).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Where should Count <- 0 be placed when counting in a loop?
Before the loop startsInside the loop, at the top
Matches
FOR N <- 1 TO 10 Count <- 0 Count <- Count + 1 NEXT N
↓
Count is set to 0 inside the loop, so it resets on every repeat and never counts beyond 1. Count <- 0 must go before the loop.
Applying
Meanings
Term
Count <- Count + 1
Meaning
Adds 1 to the counter each time the thing being counted happens. Set Count <- 0 before the loop, and put this inside the loop (inside an IF to count only some values).
Practice
Count <- 0
Testing
Gaps
Count <-
Check Answer
Spots
1DECLARE Count : INTEGER
2Count <- 1

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

The 'Thorny Devil' badge — Detail Master, 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 Count <- 0 be placed when counting in a loop?
A. Before the loop starts ✓
B. Inside the loop, at the top
The counter must be set to 0 once, before the loop. If it were inside the loop, it would reset to 0 on every repeat and you would lose the count.
2. Which statement adds 1 to a counter?
A. Count + 1 <- Count
B. Count <- Count + 1 ✓
The variable being changed goes on the left of the arrow. Count <- Count + 1 takes the old value, adds 1 and stores it back in Count.
3. A loop runs 5 times and contains Count <- Count + 1 (not inside an IF). Count started at 0. What is Count at the end?
A. 1
B. 5 ✓
Count goes up by 1 on every repeat: 0, 1, 2, 3, 4, 5. Counting every repeat gives the same number as the number of loops.
4. To count only the marks that are 50 or more, where does Count <- Count + 1 go?
A. Inside an IF Mark >= 50 THEN ✓
B. Outside the IF, directly in the loop
If the count is outside the IF, it adds 1 for every mark. Putting it inside the IF means it only runs when the condition is true.
5. Which loop body counts only the values that are greater than 10?
A. IF Num > 10 THEN Count <- Count + 1 ENDIF ✓
B. Count <- Count + 1 IF Num > 10 THEN ENDIF
The counting line must be between THEN and ENDIF so the condition controls it. In the wrong answer the IF is empty, so every value is counted.

Match the Pairs

Count <- 0 → Sets the counter to zero before the loop starts, so counting begins from nothing
Count <- Count + 1 → Adds 1 to the counter each time the thing being counted happens
To count only the marks that are 50 or more, put the counter increase inside an IF inside the loop → IF Mark >= 50 THEN Count <- Count + 1 ENDIF
To count every repeat of a loop, the counter increase goes in the loop with no IF → FOR N <- 1 TO 10 Count <- Count + 1 NEXT N
FOR N <- 1 TO 10 Count <- 0 Count <- Count + 1 NEXT N → Count is set to 0 inside the loop, so it resets on every repeat and never counts beyond 1. Count <- 0 must go before the loop.
Count <- 0 WHILE Count < 5 DO Count <- Count + 1 ENDWHILE → The counter increase is outside any IF, so it counts every repeat instead of only values that meet a condition. It should be placed inside an IF.

Key Term

Count <- Count + 1
Adds 1 to the counter each time the thing being counted happens. Set Count <- 0 before the loop, and put this inside the loop (inside an IF to count only some values).

Fill in the Blanks

1. Count <- 0 FOR Num <- 1 TO 10 Count <- Count + 1
Hint: Type the starting value the counter is given before the loop begins.
2. Count <- 0 WHILE Num < 10 DO Count <- Count + 1
Hint: Type the arithmetic operator that makes the counter go up by one each repeat.
3. FOR Num <- 1 TO 10 IF Num > 5 THEN Count <- Count + 1
Hint: Type the selection keyword so only some values are counted.
4. INPUT Mark IF Mark >= 50 THEN Count <- Count + 1
Hint: Type the relational operator that means 'at least' so passing marks are counted.
5. IF Score = 100 THEN Count <- Count + 1 ENDIF
Hint: Type the counter variable that is being added to, so its old value is kept.

Spot the Error

Question 1
A DECLARE Count : INTEGER
B Count <- 1
C FOR i <- 1 TO 5
D Count <- Count + 1
E NEXT i
F OUTPUT Count
Line B — 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 i <- 1 TO 8
C Count <- Count + 1
D NEXT i
E OUTPUT Count
Line A — Count = 0 is a comparison, not an assignment. To set the counter to 0 you must write Count <- 0.
Question 3
A Count <- 0
B FOR i <- 1 UNTIL 10
C IF Mark[i] >= 50 THEN
D Count <- Count + 1
E ENDIF
F NEXT i
Line B — A FOR loop uses the keyword TO for its end value, not UNTIL. It should be FOR i <- 1 TO 10.
Question 4
A Count <- 0
B WHILE Count < 5 THEN
C INPUT Num
D Count <- Count + 1
E ENDWHILE
F OUTPUT Count
Line B — A WHILE loop header ends with DO, not THEN (THEN belongs to IF). It should be WHILE Count < 5 DO.
Question 5
A Count <- 0
B FOR i <- 1 TO 20
C Count <- Count + i
D NEXT i
E OUTPUT Count
Line C — Adding i makes a running total, not a count. A counter must add exactly 1 each time: Count <- Count + 1.

Student with a class code? Join your class →