🔒

Unlock Pro

Subscribe to access all 59 Edexcel 1CP2 lessons.

£7.99/month
or £59/year
📖 Paper 1 · Topic 2: Computational Thinking
2.5 Subroutines — Functions & Procedures
Edexcel 1CP2 · GCSE Computer Science · ~10 min read · 🔒 Pro
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz
⭐ Enrichment lesson — this topic is not assessed in the Edexcel 1CP2 GCSE exam. It provides valuable extra knowledge but should not replace revision of the core specification.

What is a Subroutine?

A subroutine is a named block of code designed to perform a specific task that can be called from anywhere in a program. Subroutines avoid repeating code and make programs easier to read, test, and maintain.

There are two types of subroutine in Edexcel 1CP2:

TypeReturns a value?Edexcel pseudocodeExample
FunctionYes — returns a single valueFUNCTION … RETURN … ENDFUNCTIONcalculateArea(r)
ProcedureNo — performs actions without returning a valuePROCEDURE … ENDPROCEDUREprintGreeting(name)

Parameters and Arguments

  • A parameter is a variable listed in the subroutine definition — a placeholder for the value passed in
  • An argument is the actual value passed to the subroutine when it is called

FUNCTION square(n : INTEGER) : INTEGER
  RETURN n * n
ENDFUNCTION

result ← square(5) // argument = 5, returns 25

Local and Global Variables

TypeScopeDescription
Local variableInside the subroutine onlyCreated when the subroutine is called, destroyed when it ends. Cannot be accessed outside. Prevents unintended side effects.
Global variableWhole programDeclared outside all subroutines. Can be read/modified from anywhere. Can cause bugs if accidentally changed.

Benefits of Using Subroutines

  • Avoids code repetition — write once, call many times (DRY: Don't Repeat Yourself)
  • Easier to test — test each subroutine independently
  • Easier to maintain — change behaviour in one place, updates everywhere it is called
  • Easier to read — meaningful names explain what each section does
  • Team working — different programmers can write different subroutines simultaneously
  • Re-usable — subroutines can be used in other programs (libraries)

Edexcel Pseudocode Examples

Procedure:

PROCEDURE greetUser(name : STRING)
  OUTPUT "Hello, " + name
ENDPROCEDURE

CALL greetUser("Alice") // outputs: Hello, Alice

Function:

FUNCTION circleArea(r : REAL) : REAL
  RETURN 3.14159 * r * r
ENDFUNCTION

area ← circleArea(5) // returns 78.54

Exam tip: The key difference between function and procedure: a function returns a value; a procedure does not. A local variable only exists within the subroutine where it is declared — you cannot access it from outside.
⚠️ Common Mistakes
  • Saying a procedure "returns" a value — procedures perform actions; only functions return values
  • Confusing parameters (in definition) and arguments (in call)
  • Thinking local variables still exist after the subroutine ends — they are destroyed
  • Overusing global variables — this makes programs harder to debug and maintain
Video coming soon
Click slide or press arrow keys to navigate

✍️ Worksheet — 2.5 Subroutines

8 questions · Functions & Procedures

Q1Define the term 'subroutine'. State TWO benefits of using subroutines.[3]
✅ Mark scheme
A subroutine is a named block of code that performs a specific task and can be called from anywhere in a program [1]; any two of: avoids code repetition [1]; easier to test [1]; easier to maintain [1]; code is more readable [1]; can be reused in other programs [1].
Q2What is the difference between a function and a procedure?[2]
✅ Mark scheme
A function returns a value to where it was called [1]; a procedure performs an action but does not return a value [1].
Q3Distinguish between a parameter and an argument, using an example.[3]
✅ Mark scheme
A parameter is a variable in the subroutine definition (placeholder) [1]; an argument is the actual value passed when the subroutine is called [1]; e.g. FUNCTION square(n) — n is a parameter; square(5) — 5 is the argument [1].
Q4What is a local variable? State ONE advantage of using local variables.[3]
✅ Mark scheme
A local variable is declared inside a subroutine and only exists for the duration of that subroutine call [2]; advantage: prevents accidental modification from elsewhere in the program, reducing bugs [1].
Q5A program calculates exam grades for 200 students. Explain why using a function called calculateGrade(score) is better than repeating the grade calculation logic 200 times.[3]
✅ Mark scheme
If the grade boundaries change, only the function needs updating rather than 200 places [1]; avoids errors from repeating code (only one version can have bugs) [1]; the code is shorter, easier to read and test [1].
Q6Write pseudocode for a function called maximum that takes two integers a and b and returns the larger value.[3]
✅ Mark scheme
FUNCTION maximum(a : INTEGER, b : INTEGER) : INTEGER [1]; IF a > b THEN RETURN a ELSE RETURN b ENDIF [2]; or equivalent logic using MAX.
Q7State the difference between a local and a global variable in terms of scope.[2]
✅ Mark scheme
A local variable is only accessible within the subroutine where it is declared [1]; a global variable is accessible from anywhere in the entire program [1].
Q8Give ONE disadvantage of using global variables in a large program.[2]
✅ Mark scheme
Any one: any part of the program can accidentally modify a global variable, causing hard-to-find bugs [1]; makes programs harder to test and debug because the variable's value can be changed from many different places [1].
Topic Quiz
Q 1 of 15
You scored
out of 15
Click to reveal definition
🎉
Session complete!
TermDefinition
🎯

Mini Test — Subroutines

10 minutes · Exam-style

← 2.4b Lists, Stacks & QueuesTopic 2 · Computational ThinkingNext: Topic 3 →