A subroutine is a named block of code that performs a specific task. It can be called (invoked) from any part of the program, allowing code reuse and modular design.
AQA 7517 recognises two types of subroutine:
| Type | Description | Returns a value? |
|---|---|---|
| Procedure | Performs a task without returning a value; used for its side effects (e.g. printing output) | No |
| Function | Performs a task AND returns a value back to the caller | Yes |
PROCEDURE greet(name : STRING)
OUTPUT "Hello, " & name
ENDPROCEDURE
// Calling the procedure:
CALL greet("Ada")
FUNCTION square(n : INTEGER) RETURNS INTEGER
RETURN n * n
ENDFUNCTION
// Calling the function:
result ← square(5) // result = 25
Parameters are the variables listed in the subroutine definition — they receive values when the subroutine is called.
Arguments are the actual values passed to a subroutine when it is called.
Example: in PROCEDURE greet(name : STRING), name is the parameter. When we call CALL greet("Ada"), "Ada" is the argument.
| Method | Description | Original variable affected? |
|---|---|---|
| By value | A copy of the argument is passed — changes inside the subroutine do NOT affect the original | No |
| By reference | The memory address of the variable is passed — changes inside DO affect the original | Yes |
In AQA A-Level, passing by value is the default. Passing by reference requires explicit marking (BYREF keyword or indicated in the question).
FUNCTION add(a : INTEGER, b : INTEGER) RETURNS INTEGER
RETURN a + b
ENDFUNCTION
total ← add(3, 7) // total = 10
Parameters and local variables inside a subroutine have local scope — they exist only within the subroutine and are destroyed when it returns. Global variables declared outside subroutines are accessible everywhere.
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes