← IGCSE Computer Science Paper 2

Completing a partly written algorithm

Fill each missing line or value by asking what the standard method (total, count, max, search, sort) needs at that point: start value, loop bound, condition or closing keyword.

Understanding Completing a partly written algorithm in IGCSE Computer Science Paper 2

What it does: Every IF...THEN must be closed with ENDIF before the loop's NEXT, so the counting step only happens when the condition is true. A total must start at 0 so the first mark added is not changed. Starting at 1 would make the answer too big by 1. The loop bound must reach the last index. Stopping at 29 would skip the 30th name. More than 50 means greater than (>). Using >= would also count marks that are exactly 50. A WHILE ... DO loop ends with ENDWHILE. UNTIL belongs to a REPEAT loop. A totalling algorithm needs its running total set to 0 before the loop, otherwise the answer starts from a wrong or unknown value.

Common mistakes: To find the maximum, the condition must check for a score greater than Max. Using < would find the minimum instead. It should be IF Score[i] > Max THEN. A counter must start at 0 so that it counts only the items that meet the condition. Starting at 1 makes the final count one too high. It should be 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 307–316) and word search (Modules 296–316).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A totalling loop adds 10 marks. What goes in the missing line? ___ FOR Index ← 1 TO 10 Total ← Total + Mark[Index] NEXT Index
Total ← 0Total ← 1
Matches
Max ← 0 FOR i ← 0 TO 4 IF Marks[i] > Max THEN Max ← Marks[i] ENDIF NEXT i
↓
Max starts at 0, which fails if all values are negative. Max should start as the first array element, Marks[0].
Applying
Meanings
Term
complete the algorithm
Meaning
Fill each missing line or value by asking what the standard method (total, count, max, search, sort) needs at that point: start value, loop bound, condition or closing keyword.
Practice
DECLARE Marks : ARRAY[1:5] OF INTEGER
Testing
Gaps
Total ←
Check Answer
Spots
2FOR i ← 2 TO 8
3 IF Score[i] < Max THEN

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

The 'Abyssal Dragon' badge — Deep Sea Legend, 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. A totalling loop adds 10 marks. What goes in the missing line? ___ FOR Index ← 1 TO 10 Total ← Total + Mark[Index] NEXT Index
A. Total ← 1
B. Total ← 0 ✓
A total must start at 0 so the first mark added is not changed. Starting at 1 would make the answer too big by 1.
2. Finding the maximum in Mark[1:5]. Which start value is best for Max before the loop?
A. Max ← Mark[1] ✓
B. Max ← 100
Start Max with the first array item so it is always a real value from the list. A start value of 100 would never be beaten by any mark, so it would stay at 100.
3. Name[1:30] holds 30 names and every one must be checked. Which loop line is missing the right bound?
A. FOR Index ← 1 TO 29
B. FOR Index ← 1 TO 30 ✓
The loop bound must reach the last index. Stopping at 29 would skip the 30th name.
4. Count the marks that are MORE than 50. Which condition completes the line? IF Mark[Index] ___ 50 THEN
A. > ✓
B. >=
More than 50 means greater than (>). Using >= would also count marks that are exactly 50.
5. A FOR loop contains an IF ... THEN statement. The IF is complete, but the line IF Score > Max THEN has no closing line. Which keyword is missing?
A. ENDIF ✓
B. NEXT
Every IF must be closed with ENDIF. NEXT closes a FOR loop, not an IF.

Match the Pairs

Total ← ___ FOR i ← 0 TO 4 Total ← Total + Marks[i] NEXT i → The blank must be 0, so the total starts empty before any marks are added
FOR i ← 0 TO ___ OUTPUT Marks[i] NEXT i → The blank must be the last index of the array, such as 4 for an array of 5 items
A counting algorithm needs a closing keyword for its IF statement inside the loop, so the missing line is ENDIF → FOR i ← 0 TO 9 IF Score[i] > 50 THEN Count ← Count + 1 ENDIF NEXT i
A linear search with a WHILE loop must keep going only while the item is not found and the end of the list is not reached → WHILE Found = FALSE AND i <= 9 DO IF Names[i] = Target THEN Found ← TRUE ENDIF i ← i + 1 ENDWHILE
Max ← 0 FOR i ← 0 TO 4 IF Marks[i] > Max THEN Max ← Marks[i] ENDIF NEXT i → Max starts at 0, which fails if all values are negative. Max should start as the first array element, Marks[0].
REPEAT INPUT Num Total ← Total + Num ENDWHILE → The wrong closing keyword is used. A REPEAT loop must end with UNTIL and a condition, not ENDWHILE.

Key Term

complete the algorithm
Fill each missing line or value by asking what the standard method (total, count, max, search, sort) needs at that point: start value, loop bound, condition or closing keyword.

Fill in the Blanks

1. Total ← 0 FOR Index ← 1 TO 5 Total ← Total + Num[Index]
Hint: Type the start value a running total needs before the loop begins.
2. DECLARE Mark : ARRAY[1:10] OF INTEGER FOR Index ← 1 TO 10 Total ← Total + Mark[Index]
Hint: Type the final index so the loop visits every element of the declared array.
3. IF Mark[Index] > Max THEN Max ← Mark[Index] ENDIF
Hint: Type the comparison operator that spots a value bigger than the current highest.
4. FOR Index ← 1 TO 10 Total ← Total + Mark[Index] NEXT Index
Hint: Type the keyword that closes a FOR loop.
5. REPEAT INPUT Guess UNTIL Guess = 42
Hint: Type the keyword that ends a loop which runs once first and checks its condition at the end.

Spot the Error

Question 1
A Max ← Score[1]
B FOR i ← 2 TO 8
C IF Score[i] < Max THEN
D Max ← Score[i]
E ENDIF
F NEXT i
Line C — To find the maximum, the condition must check for a score greater than Max. Using < would find the minimum instead. It should be IF Score[i] > Max THEN.
Question 2
A Count ← 1
B FOR i ← 1 TO 10
C IF Mark[i] > 50 THEN
D Count ← Count + 1
E ENDIF
F NEXT i
Line A — A counter must start at 0 so that it counts only the items that meet the condition. Starting at 1 makes the final count one too high. It should be Count ← 0.
Question 3
A Sum ← 0
B FOR i ← 1 TO 4
C INPUT Mark
D Sum ← Sum + Mark
E NEXT i
F OUTPUT Sum / 5
Line B — There are 5 marks, so the loop bound must be 5. With TO 4 the last mark is never added, but the total is still divided by 5. It should be FOR i ← 1 TO 5.
Question 4
A Total ← 0
B FOR i ← 1 TO 10
C Total ← Total + Mark[i]
D ENDFOR
E OUTPUT Total
Line D — In Cambridge pseudocode a FOR loop is closed with NEXT, not ENDFOR. The line should be NEXT i.
Question 5
A Min ← 0
B FOR i ← 2 TO 7
C IF Temp[i] < Min THEN
D Min ← Temp[i]
E ENDIF
F NEXT i
Line A — The minimum must start as the first item in the array. Starting at 0 means no temperature above 0 can ever be smaller, so the result would be wrong. It should be Min ← Temp[1].

Student with a class code? Join your class →