GCSE · Computer Science · AQA · Spec 8525
Concept of subroutines
Some of the most useful code in a program doesn't run when the program starts. It just sits there. Waiting. Until something calls its name.
Computer Science · Subroutines
Follow the highlight
A tiny game program. levelUp is written once, at the top, and called twice further down. Press Next and watch where the highlighted line goes.
Keep this question in your head as you step: when levelUp reaches ENDSUBROUTINE on line 4, which line runs next?
1 SUBROUTINE levelUp()2 OUTPUT "* * * * *"3 OUTPUT "Level complete!"4 ENDSUBROUTINE5 # main program6 level ← 17 levelUp()8 level ← 29 levelUp()10 OUTPUT "You win!"
Variables
Output
Step 1: The program starts here, on line 6. Lines 1–4 were skipped: they only define levelUp, and defining a subroutine doesn't run it.
Use Next and Back. Watch the highlight leave the main program — and come back.
Name the parts
Explore
Tap a part of the program.
One subroutine definition at the top, then the main program underneath.
Same program you just stepped through. Tap each part to see what it's called and what it does.
Two kinds of subroutine
Procedure or function?
Sort each subroutine, or each call, into the right column.
Still to sort
Procedure (0)
Carries out a task. Sends no value back.
Where the line is: Putting something on the screen doesn't count as sending a value back. Nothing reaches the code that made the call.
Function (0)
Carries out a task and returns a value to the caller.
Where the line is: Because a value comes back, a function call can be used where a value is needed — inside an assignment or an expression.
One test settles every one: does the subroutine send a value back to the code that called it?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Writing a subroutine doesn't run it. Calling it does — and when it's finished, the program picks up exactly where it left off.
What you need to know
- A subroutine is a self-contained block of code that carries out one specific task.
- It has its own identifier — its name — and it's written separately from the main program, not in line with it.
- Here's the twist: defining a subroutine doesn't run it. Nothing inside it happens yet.
Have a goYour mate writes a 40-line subroutine called fireworks() at the very top of their program, never mentions it again, and hits Run. How many fireworks go off?
None — not a single line of fireworks() runs.
Writing a subroutine only defines it. Being at the top of the file doesn't make it run — and nothing in the program ever asks it to.
- Its statements run only when another part of the program calls it by its identifier, like levelUp().
- At a call, control jumps from the calling statement to the subroutine's first statement.
- When the subroutine finishes, control comes back to the point just after the call, and the program carries on from there.
Have a goLine 7 of a main program calls tidy(). Line 8 is OUTPUT "Saved". tidy() has just run its last statement. Which runs next: line 8, or whatever is written under tidy()'s ENDSUBROUTINE?
Line 8, OUTPUT "Saved".
Control goes back to just after the call that sent it away, not to whatever happens to be written below the subroutine's definition.
- You can call the same subroutine as many times as you like, from different places. Each call comes back to just after itself.
- One subroutine can call another. The inner one hands control back to the outer one first.
- A procedure carries out a task but sends no value back to the code that called it.
- A function carries out a task and returns a value to its caller, so its call can sit inside an expression or assignment.
Have a goWhich line proves that score() must be a function: score() standing on a line by itself, or total ← score() + 1?
total ← score() + 1
The sum needs a value to come back from the call. A call standing alone could be a procedure or a function, so on its own it proves nothing.
The big picture
A subroutine is a named, self-contained block of code that does one job, written apart from the main program. Defining it doesn't run it — a call does. The call sends control to the subroutine's first statement; when it finishes, control comes back to just after the call. You can call the same subroutine many times, from different places, and one subroutine can call another. A procedure sends no value back; a function returns a value to its caller, so a function call can sit inside an assignment or expression.
Key points
Worked example
Problem
Here is a program: 1 SUBROUTINE divider() 2 OUTPUT "-----" 3 ENDSUBROUTINE 4 SUBROUTINE banner() 5 divider() 6 OUTPUT "QUIZ TIME" 7 divider() 8 ENDSUBROUTINE 9 # main program 10 banner() 11 OUTPUT "Question 1" 12 divider() Write down everything the program outputs, in order.
⚠ Watch out
Reading a program straight down the page like a story — so the subroutine seems to run where it's written, and the program seems to carry on after ENDSUBROUTINE. Follow the calls instead: a subroutine runs when it's called, then control comes back to just after that call.
Memory hook
Call, jump in, run, jump back. Every return lands on the line just after its own call — and a function brings a value back with it.
Check yourself
beep() outputs "Beep". A main program runs beep(), OUTPUT "Hi", then beep(). Write the full output. Is beep() a procedure or a function — and how can you tell?
Flashcards
(11)What is a subroutine?
What is a subroutine's identifier used for?
Does defining a subroutine run it?
When a subroutine is called, where does control go?
When a subroutine finishes, where does the program carry on from?
Can the same subroutine be called more than once?
Subroutine A calls subroutine B. When B finishes, where does control go?
What is a procedure?
What is a function?
Why can only a function call appear on the right of an assignment, like x ← f()?
A subroutine OUTPUTs a number. Does that make it a function?
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.