One pass of a bubble sort
One pass: a FOR loop compares each item with its neighbour and swaps them if the first is larger, so the biggest value moves to the end.
Understanding One pass of a bubble sort in IGCSE Computer Science Paper 2
What it does: Using < instead of > swaps pairs when the first is smaller, so the smallest value is pushed to the end and the list ends up in descending order. A pass compares an item with the NEXT one, Marks[Index + 1]. Comparing Marks[Index] with itself never swaps anything. A swap only happens if Marks[Index] > Marks[Index + 1]. Putting it after ENDIF would swap every pair, even ones already in order. One pass compares 5,9 (no swap), then 9,2 (swap), then 9,7 (swap). The biggest value, 9, moves to the end, but the array is not yet fully sorted. The comparison uses Index + 1, so the final Index must be n - 1 to keep the neighbour inside the array.
Common mistakes: Num[i] is compared with itself, so the condition is never true and nothing is ever swapped. It should compare with the neighbour: IF Num[i] > Num[i + 1] THEN. This puts the old Num[i] back where it started, so Num[i + 1] never changes and the swap fails. The last swap line should be Num[i + 1] ← Temp.
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 296–306) 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.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
IF Marks[Index] > Marks[Index + 1] THENFill in the Blanks
Spot the Error
Student with a class code? Join your class →