Finding and fixing errors in subroutine code
Finding and fixing errors by checking a subroutine's header, parameter types, RETURN, CALL, end keyword and variable scope against the syntax rules.
Understanding Finding and fixing errors in subroutine code in IGCSE Computer Science Paper 2
What it does: This function is correct because it has a RETURN and finishes with the matching end keyword ENDFUNCTION. Result is local, so it cannot be used outside the function. RETURN Result sends its value back to the caller. The number of values in a call must match the number of parameters. The correct call is CALL Greet("Sam", 15). A function call is used inside an expression, such as OUTPUT or an assignment. CALL is used for procedures. The header lists one parameter, so the call must give exactly one argument, such as CALL ShowTotal(5). Local variables only exist within their own subroutine. Moving OUTPUT Sum inside the procedure fixes the scope error.
Common mistakes: The function header is missing the RETURNS keyword. A function header must state the return type as RETURNS INTEGER. The parameter Name has no data type. Each parameter in the header needs a type, so it should be Name : STRING.
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
DebuggingFill in the Blanks
Spot the Error
Student with a class code? Join your class →