GCSE · Computer Science · AQA · Spec 8525
Return values
A mate works out 2 × 8 + 3 × 5 and shouts "31!" Don't write it down, and it's gone. Function calls work just like that.
Computer Science · Programming
Follow one call there and back
Step through the program. Watch control jump into ticket_cost, then jump back with a value.
Before you press Next: what number ends up in total?
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 to 4 only define ticket_cost. Nothing inside it runs until something calls it. So the first real action is line 5, which calls it and hands in 2 and 3.
Use Next and Back. Keep an eye on the line that made the call: each time the subroutine returns, that line carries on with a number where the call used to be.
Predict, then check
This function has two return statements. Only one of them gets to send a value back.
grade(score) starts with 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 heads off, does some work, and comes back as a value. Your job? Catch it.
What you need to know
- A subroutine is a named, self-contained block of code that you can call from elsewhere in your program.
- Subroutines that send a value back are usually called functions. Ones that don't are usually called procedures.
Have a goYour mate Zac insists print_receipt must be a function "because it does loads of maths". It adds up a total and displays it, but sends nothing back. What's it usually called?
A procedure.
Doing maths doesn't decide it. What decides it is whether a value comes back, and nothing does, so Zac's "function" is usually called a procedure.
- A return value is what the subroutine sends back to the part of the program that called it, when it finishes.
- Arguments go in through the parameters, the body runs, then the return statement sends the value back out.
- Once a return statement runs, the subroutine is over. Any lines after it in that subroutine don't run.
Have a goA function's body is just two lines: RETURN 5, then RETURN 9. What does a call to it send back?
5
The first return statement that runs ends the subroutine, so RETURN 9 is never reached. A later return doesn't get to overwrite an earlier one.
- Back where it was called, the call stands in for its value: total = ticket_cost(2, 3) works like total = 31.
- You can use the call anywhere a value of that type is expected: a variable, an expression, a condition, or another call's argument.
- If the calling code doesn't store or use the returned value, it's simply lost.
Have a gox = 4. The next line is just double(x) on its own, and double returns 8. Rewrite that second line so x ends up holding 8.
x = double(x)
The 8 came back, but nothing caught it, so it was lost. Handing x in as the argument doesn't change x; storing the call's value does.
- Parameters in, return value out: the subroutine works from its inputs, so the calling code needn't rely on global variables.
- To trace, swap each call for the value it returns. When one call sits inside another, the inner one returns first.
The big picture
A subroutine is a named, self-contained block of code you can call from elsewhere; ones that send a value back are usually called functions, ones that don't are usually called procedures. Arguments go in through the parameters, and an executed return statement ends the subroutine and sends its value back to the call site, where the call stands in for that value wherever a value of that type fits. Store or use it, or it's lost. Parameters in, return value out: no reliance on global variables.
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
Treating RETURN like OUTPUT. RETURN ends the subroutine and sends a value back to the calling code; it displays nothing. And a call on a line by itself loses that value: the variable you passed in doesn't change.
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 real boomerang, it brings back something new: its result.)
Check yourself
double(n) returns n * 2. What value does double(double(3)) have, and which of the two calls finishes first? Then write one line that keeps that value in a variable called d.
Flashcards
(11)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 a return statement display a value on the screen?
What is an argument?
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 27 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.