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 waits — until something calls it.
Computer Science · Subroutines
Follow the highlight
A tiny game program. The subroutine 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.
It's the 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 decides 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
- What a subroutine is, and what its identifier is for
- Why defining a subroutine doesn't make it run
- Where control goes when a subroutine is called, and where it comes back to when it finishes
- How to trace a subroutine that is called more than once, or that calls another subroutine
- The difference between a procedure and a function
The big picture
Subroutines are named, self-contained blocks of code, each doing one job, written apart from the main program. Defining one doesn't run it; a call does. The call sends control to the subroutine's first statement, and when it finishes, control returns to just after the call. A subroutine can be called many times, from different places, and can call another subroutine. A procedure sends no value back; a function returns a value to its caller, so its 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
Tracing a program straight down the page, so the subroutine runs where it's written and the program carries on after ENDSUBROUTINE. Follow the calls: a subroutine runs when called, then control returns to just after the 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 29 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.