← IGCSE Computer Science Paper 2

Finding the maximum in Cambridge pseudocode

Used inside a loop to compare each mark with Largest. If the mark is bigger, it replaces Largest. When the loop ends, Largest holds the biggest value in the array.

Understanding Finding the maximum in Cambridge pseudocode in IGCSE Computer Science Paper 2

What it does: Starting at 2 avoids comparing Marks[1] with itself, since Largest ← Marks[1] has already been done. Updating Position at the same time as Largest means Position always holds the index of the biggest value found so far. A new mark replaces Largest only when it is bigger. Using < would find the smallest value instead. Largest is only the true maximum after every element has been checked. Output after the loop gives one answer. Output inside the loop prints values that may not be the maximum yet. Largest starts at 40, becomes 75 as 75 > 40, then stays 75 because 60 is not greater than 75. The last value checked is not automatically the largest.

Common mistakes: The comparison is the wrong way round. Using < only updates Largest when a mark is smaller, so it would find the minimum. It should be IF Marks[Index]>Largest THEN. Cambridge pseudocode arrays start at index 1, so Marks[0] does not exist. Largest should start as the first mark: Largest ← Marks[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 286–295) and word search (Modules 275–295).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly sets up the maximum BEFORE the loop starts?
Largest ← 0 (always safe, whatever the marks are)Largest ← Marks[1]
Matches
FOR Index ← 2 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF NEXT Index OUTPUT Largest (Largest was never set before the loop)
↓
Largest has no starting value, so the first comparison uses an undefined value. It should be set first with Largest ← Marks[1].
Applying
Meanings
Term
IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF
Meaning
Used inside a loop to compare each mark with Largest. If the mark is bigger, it replaces Largest. When the loop ends, Largest holds the biggest value in the array.
Practice
Largest ← Marks[1]
Testing
Gaps
Largest ← Marks[]
Check Answer
Spots
2FOR Index ← 2 TO 10
3 IF Marks[Index]<Largest THEN

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

The 'Leopard' badge — Savannah Perfectionist, 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 correctly sets up the maximum BEFORE the loop starts?
A. Largest ← 0 (always safe, whatever the marks are)
B. Largest ← Marks[1] ✓
Starting with the first element means Largest is always a real value from the array. Starting at 0 only works if every mark is above 0, so it is not a safe method.
2. Marks has 10 elements and Largest ← Marks[1] has already been done. Which loop header is best?
A. FOR Index ← 2 TO 10 ✓
B. FOR Index ← 0 TO 10
Marks[1] is already stored in Largest, so the loop starts at 2. Index 0 does not exist in Cambridge arrays that start at 1, so it would cause an error.
3. Which IF statement keeps the biggest value inside the loop?
A. IF Marks[Index] < Largest THEN
B. IF Marks[Index] > Largest THEN ✓
A new mark replaces Largest only when it is bigger. Using < would find the smallest value instead.
4. What goes inside the IF when a bigger mark is found?
A. Largest ← Marks[Index] ✓
B. Marks[Index] ← Largest
The arrow copies the value on its right into the variable on its left. Largest must receive the new mark. The wrong version overwrites the array element with the old largest value.
5. Where should OUTPUT Largest be placed?
A. After NEXT Index, once the loop has finished ✓
B. Inside the loop, before the IF
Largest is only the true maximum after every element has been checked. Output after the loop gives one answer. Output inside the loop prints values that may not be the maximum yet.

Match the Pairs

Largest ← Marks[1] → Start by assuming the first mark is the biggest so far, so Largest has a real value from the array to compare against.
IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF → Compare the current mark with Largest and replace Largest only if the current mark is bigger.
The loop can start at the second element because the first element was already stored in Largest. → FOR Index ← 2 TO 10
To also record where the maximum is, save the Index whenever a new largest value is found. → IF Marks[Index] > Largest THEN Largest ← Marks[Index] Position ← Index ENDIF
FOR Index ← 2 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF NEXT Index OUTPUT Largest (Largest was never set before the loop) → Largest has no starting value, so the first comparison uses an undefined value. It should be set first with Largest ← Marks[1].
FOR Index ← 2 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF OUTPUT Largest NEXT Index → OUTPUT Largest is inside the loop, so it prints after every item. It should come after NEXT Index so the final maximum is output once.

Key Term

IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF
Used inside a loop to compare each mark with Largest. If the mark is bigger, it replaces Largest. When the loop ends, Largest holds the biggest value in the array.

Fill in the Blanks

1. Largest ← Marks[1]
Hint: Type the index of the first element, used to start Largest.
2. FOR Index ← 2 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index]
Hint: Type the starting value of Index. Element 1 is already stored in Largest.
3. FOR Index ← 2 TO 10 IF Marks[Index] > Largest THEN Largest ← Marks[Index]
Hint: Type the comparison operator that checks whether the current mark is bigger than Largest.
4. IF Marks[Index] > Largest THEN Largest ← Marks[Index] ENDIF
Hint: Type the loop variable that picks the current element, which replaces Largest when it is bigger.
5. NEXT Index OUTPUT Largest
Hint: Type the keyword that displays the result once the loop has finished.

Spot the Error

Question 1
A Largest ← Marks[1]
B FOR Index ← 2 TO 10
C IF Marks[Index]<Largest THEN
D Largest ← Marks[Index]
E ENDIF
F NEXT Index
Line C — The comparison is the wrong way round. Using < only updates Largest when a mark is smaller, so it would find the minimum. It should be IF Marks[Index]>Largest THEN.
Question 2
A Largest ← Marks[0]
B FOR Index ← 2 TO 10
C IF Marks[Index]>Largest THEN
D Largest ← Marks[Index]
E ENDIF
F NEXT Index
Line A — Cambridge pseudocode arrays start at index 1, so Marks[0] does not exist. Largest should start as the first mark: Largest ← Marks[1].
Question 3
A Largest ← Marks[1]
B FOR Index ← 2 TO 11
C IF Marks[Index]>Largest THEN
D Largest ← Marks[Index]
E ENDIF
F NEXT Index
Line B — The array only has 10 marks, so Marks[11] does not exist and the loop would go out of bounds. The loop should end at 10: FOR Index ← 2 TO 10.
Question 4
A FOR Index ← 2 TO 10
B IF Marks[Index]>Marks[1] THEN
C Largest ← Marks[Index]
D Position ← Index
E ENDIF
F NEXT Index
Line B — Each mark must be compared with Largest, which holds the biggest value so far, not always with the first mark. It should be IF Marks[Index]>Largest THEN.
Question 5
A FOR Index ← 2 TO 10 STEP 2
B IF Marks[Index]>Largest THEN
C Largest ← Marks[Index]
D ENDIF
E NEXT Index
F OUTPUT Largest
Line A — STEP 2 makes the loop skip every other mark, so the biggest mark could be missed. Every element must be checked, so remove STEP 2.

Student with a class code? Join your class →