GCSE · Computer Science · AQA · Spec 8525
Procedures and functions
Nobody writes the same calculation fifty times. They write it once, give it a name and call it, and today you'll watch one of those calls happen, step by step.
Computer Science · Subroutines
Follow the call: into bonus and back again
Press Next and keep your eye on the highlighted line. Where does the program go? Where does each value land? What comes back?
Predict before you press Next: what will score hold when the program reaches OUTPUT?
1 SUBROUTINE bonus(points, level)2 extra ← points * level3 RETURN extra4 ENDSUBROUTINE5 score ← 506 score ← score + bonus(10, 3)7 OUTPUT score
Variables
Output
Step 1: The program starts in the main program, at line 5. Lines 1 to 4 only define bonus. Defining a subroutine doesn't run it.
Watch the Variables panel: points, level and extra appear when bonus starts, and vanish when it returns.
Computer Science · Subroutines
Procedure or function?
Pick a subroutine, then choose its kind. Each one is shown by its name and what its body does.
Still to sort
Function (0)
Returns a value to the code that called it.
Where the line is: RETURN sends a value back to the caller. Showing a value on screen with OUTPUT is not the same thing.
Procedure (0)
Carries out its task without returning a value.
Where the line is: A procedure can still take parameters and can still display things. It just sends nothing back.
Every subroutine is one or the other. Ask one question: does it send a value back to the caller with RETURN?
Computer Science · Structured programming
Layers
Explore
Turn Interfaces off to see the bare decomposition, then back on.
Each module's interface: the data that goes in through its parameters, and the value, if any, that comes back.
Tap a box, or its name under Explore, to read its interface: what goes in, and what comes back.
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
What you need to know
- A subroutine is a self-contained block of code with its own identifier that carries out a specific task. It runs when the main program (or another subroutine) calls it by that identifier; then control returns to where the call was made.
- Procedures and functions are the two kinds of subroutine. A function returns a value to the code that called it; a procedure carries out its task without returning a value.
- Parameters are the variables listed in a subroutine's definition. Arguments are the values supplied in the call, and they are passed to the parameters in order, so the same subroutine can work on different data.
- A function sends its result back with a return statement. The returned value replaces the call, so it can be assigned to a variable, output or used in an expression.
- A local variable is declared inside a subroutine, exists only while that subroutine runs and can only be accessed from within it. A global variable is declared in the main program and can be accessed from anywhere.
- Structured programming builds a program from modules (subroutines), each with a clear interface: the data it takes in through its parameters and the value, if any, it returns.
The big picture
A subroutine is a named, self-contained block of code that does one job. Calling it makes control jump to it; when it finishes, control comes back to where the call was made. Arguments in the call are passed to the parameters in the definition. A function returns a value, which replaces the call in the calling code; a procedure returns nothing. Local variables exist only inside their subroutine while it runs, which keeps subroutines self-contained, and structured programs are built from subroutines with clear interfaces.
Key points
Worked example
Problem
SUBROUTINE area(w, h) holds two lines: a ← w * h, then RETURN a. The main program runs x ← area(2, 5), then y ← area(x, 3) - 1, then OUTPUT y. What is output?
⚠ Watch out
Mixing up parameters and arguments. The parameters are the names in the subroutine's definition, like w and h in area(w, h). The arguments are the values in the brackets when you call it, like 2 and 5 in area(2, 5).
Memory hook
A function is a round trip that brings back a souvenir: it goes away, does the job and returns with a value. A procedure makes the same trip and comes home empty-handed.
Check yourself
Without looking back: cube(n) returns n * n * n. In y ← cube(2) - 3, where does control go at the call, which parameter gets 2, and what does y hold? (y holds 5.)
Flashcards
(13)What is a subroutine?
What happens to control when a subroutine is called?
What is the one difference between a function and a procedure?
A subroutine OUTPUTs its answer but has no RETURN. Which kind is it?
What is a parameter?
What is an argument?
How are arguments matched to parameters?
Where does a function's returned value go?
What is a local variable?
What is a global variable?
Why does using local variables make subroutines easier to reuse, test and debug?
What is structured programming?
What is a subroutine's interface?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 30 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.