GCSE · Computer Science · AQA · Spec 8525
Return values
A friend works out 2 × 8 + 3 × 5 and comes back with 31. Don't write it down, and it's gone. A function call works the same way.
Computer Science · Subroutines
Follow one call there and back
Step through the program and watch where control goes. Keep an eye on line 5: the call on that line is about to turn into a number.
What value lands in total when the call comes back?
1 FUNCTION ticket_cost(adults, children)2 cost = adults * 8 + children * 53 RETURN cost4 END FUNCTION5 total = ticket_cost(2, 3)6 solo = ticket_cost(1, 0)7 OUTPUT total8 OUTPUT solo
Variables
Output
Step 1: Lines 1–4 just set up ticket_cost; nothing inside it runs until something calls it. So the first real action is line 5, which calls it with two arguments, 2 and 3. Before you press Next: what will total end up holding?
Use Next to step. Watch the highlighted line jump into the subroutine and back out again.
Predict, then check
Here's a function with two return statements. Only one of them can send a value back.
grade(score) does this: IF score >= 50 THEN RETURN "Pass" END IF. Its last line is RETURN "Retry". What does grade(72) send back?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A function call goes off, does some work, and comes back as a value. The trick is catching it.
What you need to know
- A subroutine is a named, self-contained block of code that can be called from elsewhere in a program. Ones that return a value are usually called functions; ones that don't are usually called procedures.
- A return value is the value a subroutine sends back to the part of the program that called it, when the subroutine finishes.
- A return statement ends the subroutine straight away and passes the value back to where the subroutine was called. Any code after the executed return statement in that subroutine doesn't run.
- A call to a function can be used anywhere a value of that type is expected: assigned to a variable, in an expression, in a condition, or as an argument to another subroutine.
- If the calling code doesn't store or use the returned value, the value is lost.
- Parameters pass data in and the return value passes the result out, so a subroutine can work out its result without the calling code relying on global variables.
- To trace a call, put the arguments into the parameters, run the body until a return statement executes, then replace the call with the value it returns.
The big picture
A subroutine is a named, self-contained block of code you can call from elsewhere in a program. A function is a subroutine that sends a value back; a procedure doesn't. When a return statement runs, the subroutine stops and its value goes back to the exact place it was called from, so the call itself becomes that value. The calling code has to store or use it, or it's lost.
Key points
Worked example
Problem
bigger(a, b) is a function. Its first line is IF a > b THEN RETURN a END IF, and its last line is RETURN b. What value is stored in x after the line x = bigger(3, 9) + bigger(7, 2) runs?
⚠ Watch out
Calling a function on a line by itself, like add_vat(price), and expecting price to change. The value comes back and is lost. Store it, as in price = add_vat(price), or use the call inside something that needs a value.
Memory hook
A function call is a boomerang: throw it with arguments, it does its work and flies back to exactly where you threw it. Catch it, or it hits the floor. (Unlike a boomerang, it brings back something new: its result.)
Check yourself
double(n) returns n * 2. What value does double(double(3)) have? Explain which call has to finish first, and why.
Flashcards
(12)What is a subroutine?
What's the difference between a function and a procedure?
What is a return value?
What two things does a return statement do?
A return statement runs halfway through a function. What happens to the lines after it?
Where does a returned value go?
What happens to a returned value if the calling code doesn't store or use it?
Name four places you can use a call to a function that returns a value.
How do parameters and a return value work together?
Does RETURN display a value on the screen?
What is an argument?
Can a function return different values each time it's called?
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.