← IGCSE Computer Science Paper 2

Finding the minimum in Cambridge pseudocode

Inside a loop, this compares each item with Smallest and replaces Smallest when a lower value is found. Start Smallest as Marks[1], not 0, so the minimum is correct.

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

What it does: Using < means Smallest only changes when a lower value appears. Using > would find the maximum instead. Starting from Marks[1] always gives a real value from the data, so the minimum is correct for any numbers, including negatives. No positive mark is less than 0, so the IF condition is never true and Smallest never changes. Each item must be compared with Smallest. If the check is after the loop, only one item is looked at.

Common mistakes: Starting Smallest at 0 gives the wrong minimum. Marks are never below 0, so the IF would never replace it and the answer would stay 0. It should be Smallest ← Marks[1]. The assignment is the wrong way round. This overwrites the array item instead of updating Smallest. It should be THEN Smallest ← Marks[Index].

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 finds a new smallest mark inside the loop?
IF Marks[Index] > Smallest THENIF Marks[Index] < Smallest THEN
Matches
Smallest ← 0 FOR Index ← 1 TO 10 IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF NEXT Index
↓
Smallest starts at 0, so if every mark is above 0 nothing is ever smaller and the output is wrongly 0. Start with Smallest ← Marks[1].
Applying
Meanings
Term
IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF
Meaning
Inside a loop, this compares each item with Smallest and replaces Smallest when a lower value is found. Start Smallest as Marks[1], not 0, so the minimum is correct.
Practice
Smallest ← Marks[1]
Testing
Gaps
Smallest ← Marks[]
Check Answer
Spots
1Smallest ← 0
2FOR Index ← 2 TO 8

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

The 'Blue-Ringed Octopus' badge — Reef 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. Which line correctly finds a new smallest mark inside the loop?
A. IF Marks[Index] < Smallest THEN ✓
B. IF Marks[Index] > Smallest THEN
To find the minimum, replace Smallest when the current item is LESS than it. Using > would find the maximum instead.
2. Which is the best starting value for Smallest when the marks are 45, 72 and 60?
A. Smallest ← 0
B. Smallest ← Marks[1] ✓
Starting with the first item means Smallest is always a real value from the array. Starting at 0 means no mark is ever lower, so the answer stays 0.
3. What goes wrong if Smallest starts at 0 and all the marks are positive?
A. Smallest stays 0, which is not in the array ✓
B. Smallest becomes the largest mark
No positive mark is less than 0, so the IF condition is never true and Smallest never changes.
4. Which statement is true about the code inside the IF...ENDIF?
A. Smallest ← Marks[Index] runs on every pass of the loop
B. Smallest ← Marks[Index] runs only when a lower mark is found ✓
The IF condition guards the assignment. Smallest is only updated when Marks[Index] < Smallest is true.
5. Marks are 5, -3, 8, 2. Which start value for Smallest gives the correct minimum?
A. Smallest ← Marks[1] ✓
B. Smallest ← 0
Starting at 0 would give 0 as an answer only if no value below 0 is found, but starting at Marks[1] is always safe. With negative values, 0 is not a safe starting guess because it is not a real item from the array.

Match the Pairs

Smallest ← Marks[1] → Starts the minimum as the first mark in the array, so the first real value is the one to beat.
IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF → Replaces Smallest with the current mark only when that mark is lower than the smallest found so far.
To find the minimum, you must test whether the current item is LESS than Smallest, not greater. → IF Marks[Index] < Smallest THEN
Start the minimum from an actual array value, so it works even if all the marks are above 0 or are negative. → Smallest ← Marks[1]
Smallest ← 0 FOR Index ← 1 TO 10 IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF NEXT Index → Smallest starts at 0, so if every mark is above 0 nothing is ever smaller and the output is wrongly 0. Start with Smallest ← Marks[1].
IF Marks[Index] > Smallest THEN Smallest ← Marks[Index] ENDIF → The > operator is used instead of <, so this finds the largest value, not the smallest. Change it to Marks[Index] < Smallest.

Key Term

IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF
Inside a loop, this compares each item with Smallest and replaces Smallest when a lower value is found. Start Smallest as Marks[1], not 0, so the minimum is correct.

Fill in the Blanks

1. Smallest ← Marks[1]
Hint: Type the index of the first array element, so the starting value comes from the data and is never wrongly 0.
2. IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF
Hint: Type the comparison operator that checks whether the current item is lower than Smallest.
3. IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF
Hint: Type the keyword that closes the selection statement.
4. Smallest ← Marks[1] FOR Index ← 2 TO 10 IF Marks[Index] < Smallest THEN
Hint: Type the index the loop starts at, since the first item has already been stored in Smallest.
5. IF Marks[Index] < Smallest THEN Smallest ← Marks[Index] ENDIF
Hint: Type the assignment symbol that stores the new lower value in Smallest.

Spot the Error

Question 1
A Smallest ← 0
B FOR Index ← 2 TO 8
C IF Marks[Index] < Smallest
D THEN Smallest ← Marks[Index]
E ENDIF
F NEXT Index
Line A — Starting Smallest at 0 gives the wrong minimum. Marks are never below 0, so the IF would never replace it and the answer would stay 0. It should be Smallest ← Marks[1].
Question 2
A Smallest ← Marks[1]
B FOR Index ← 2 TO 10
C IF Marks[Index] < Smallest
D THEN Marks[Index] ← Smallest
E ENDIF
F NEXT Index
Line D — The assignment is the wrong way round. This overwrites the array item instead of updating Smallest. It should be THEN Smallest ← Marks[Index].
Question 3
A Smallest ← Temps[1]
B FOR Index ← 2 TO 7
C IF Temps[Index] > Smallest
D THEN Smallest ← Temps[Index]
E ENDIF
F NEXT Index
Line C — Using > finds the largest temperature, not the smallest. Even with negative values, the test must be IF Temps[Index] < Smallest.
Question 4
A Smallest ← Marks[1]
B FOR Index ← 2 TO 5
C IF Smallest < Marks[Index]
D THEN Smallest ← Marks[Index]
E ENDIF
F NEXT Index
Line C — The comparison is reversed, so Smallest is replaced by a larger value and the loop finds the maximum. It should be IF Marks[Index] < Smallest.
Question 5
A Smallest ← Scores[1]
B FOR Count ← 2 TO 6
C IF Scores[Count] < Smallest
D THEN Smallest ← Count
E ENDIF
F NEXT Count
Line D — This stores the position (Count) instead of the score. Smallest must hold the value, so it should be THEN Smallest ← Scores[Count].

Student with a class code? Join your class →