GCSE · Computer Science · AQA · Spec 8525
Procedures and functions
Typing the same code fifty times means fifty fixes when it's wrong. So you write it once, name it, and call it. Let's follow one call there and back.
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: Notice something odd? The program starts at line 5, not line 1. Lines 1 to 4 only define bonus, and defining a subroutine doesn't run it. score is set to 50.
Watch the Variables panel: points, level and extra pop into existence 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. One of them is trying to trick you.
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 just 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 switch it 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, built to do one specific task.
- Call it by its identifier and control jumps there; when it finishes, control comes back to where the call was made.
- There are two kinds. A function returns a value to the code that called it; a procedure returns nothing.
- OUTPUT is not RETURN: putting a value on the screen sends nothing back to the calling code.
- Parameters are the variables named in a subroutine's definition. Arguments are the values you put in the call.
Have a goSUBROUTINE move(steps, dir) is called as move(4, "left"). Sort the four things you can see into parameters and arguments.
Parameters: steps and dir. Arguments: 4 and "left".
Parameters are the names written in the definition; arguments are the values written in the call. Swapping the two words round is the classic slip.
- Arguments are passed to parameters in order, first to first, so one subroutine can work on different data.
- A returned value replaces the call, so you can store it in a variable, output it or use it in an expression.
Have a gosq(n) returns n * n. What does y ← sq(sq(2)) store? Work from the inside out.
16
sq(2) returns 4, and that 4 replaces the inner call, so the line becomes y ← sq(4), which returns 16. Answering 4 or 8 forgets that the returned value is fed into the outer call.
- A local variable is declared inside a subroutine, exists only while it runs and can only be accessed from inside it.
Have a goJordan's subroutine counts 12 cookies into a local variable called cookies, then finishes. Nothing else is called cookies. The main program runs OUTPUT cookies. What does Jordan learn the hard way?
The main program can't use cookies at all. It doesn't exist there.
cookies was local, so it could only be accessed inside the subroutine, and it vanished when the subroutine finished. The 12 never left; only RETURN could have sent it back.
- A global variable is declared in the main program and can be accessed from anywhere in the program.
- Structured programs are built from modules (subroutines), each with a clear interface: parameters in, returned value (if any) out.
The big picture
A subroutine is a named, self-contained block of code that does one job. Call it, and control jumps to it; when it finishes, control comes back to where the call was made. The arguments in the call are passed to the parameters in the definition, in order. A function returns a value, and that value replaces the call in the calling code; a procedure returns nothing. Local variables live 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). Definition: names. Call: values.
Memory hook
A function is a round trip that brings back a souvenir: off it goes, does the job and comes home with a value. A procedure makes the same trip and comes home empty-handed.
Check yourself
No peeking: 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
(14)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?
A rule in a calculation changes. Why is that easier if the calculation is a subroutine?
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 28 October 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.