Why local variables are preferred
A variable declared inside a subroutine. It keeps the subroutine self-contained, so changing it cannot accidentally alter other parts of the program, and the subroutine is easier to test alone.
Understanding Why local variables are preferred in IGCSE Computer Science Paper 2
What it does: Each i is local to its own subroutine, so changing one never changes the other. Because Double needs nothing from the rest of the program, it can be called with a test value and checked by itself. Local variables with the same name in different subroutines are completely separate. You can reuse names like Total or Count safely. Parameters pass values in through the call, so the subroutine does not depend on global variables that other code might change. A variable declared inside a subroutine is local to it. A variable declared in the main program, outside any subroutine, is global.
Common mistakes: The header has no parameter, so N is never passed in. The procedure would have to rely on a global variable called N. It should be PROCEDURE Twice(N : INTEGER) so the value is passed in as a parameter. The parameter is called P, but the body uses Pts. Pts is not local to the procedure, so it would only work if a global called Pts existed. The parameter name must match the name used inside: Pts.
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 419–428) and word search (Modules 419–438).
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
local variableFill in the Blanks
Spot the Error
Student with a class code? Join your class →