Bubble sort in pseudocode
A sort that makes repeated passes, comparing neighbouring items and swapping them using a Temp variable if they are in the wrong order, until a pass makes no swaps.
Understanding Bubble sort in pseudocode in IGCSE Computer Science Paper 2
What it does: Each pair uses Item[i + 1], so the last value of i must be Count - 1. Going to Count would read past the end of the array. Swapped is set to FALSE at the start of each pass. If the pass never sets it to TRUE, the array is sorted and the REPEAT loop ends. Without Temp, the first assignment overwrites Item[i], so both elements end up with the same value. Temp stores the old value first. The outer loop controls the number of passes. The inner loop does the comparing, and the swap happens inside an IF statement within it.
Common mistakes: The FOR loop must set its counter with the assignment arrow, so it should be FOR i ← 0 TO 3. In pseudocode = is used for comparison, not assignment. A DECLARE statement needs a colon between the identifier and its data type. It should be DECLARE Temp : INTEGER.
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 242–253) and word search (Modules 232–253).
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
bubble sortFill in the Blanks
Spot the Error
Student with a class code? Join your class →