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 * 5
3 RETURN cost
4 END FUNCTION
5 total = ticket_cost(2, 3)
6 solo = ticket_cost(1, 0)
7 OUTPUT total
8 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?

1 / 12

Use Next to step. Watch the highlighted line jump into the subroutine and back out again.

Step 1 of 12: 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?.

Two kinds of subroutine

FunctionvsProcedure

ticket_cost was a function. Not every subroutine hands something back, though.

Focus

What comes back

Function

A value, sent back by a return statement

Procedure

Nothing. It does its job and control carries on

The insight

This is the whole difference, and it's the one people mix up. The names are the usual ones; some languages call both kinds 'functions', so go by whether a value comes back.

What it is

Function

A named, self-contained block of code, called from elsewhere

Procedure

Also a named, self-contained block of code, called from elsewhere

A typical call

Function

total = ticket_cost(2, 3)

Procedure

print_ticket(2, 3)

Can the call stand in for a value?

Function

Yes. Once it returns, the call is the value

Procedure

No. There's no value for it to stand in for

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?

Computer Science · Where does it go?

Where does a returned value actually go?

A program runs the line price = discount(40) and the function discount works out and returns 30.

Straight after discount returns 30, where does the 30 go? Pick the one closest to what you think.
How sure are you?

Computer Science · Debugging

The value that went missing

This program should output the price after a £5 discount, which is 35. It outputs 40 instead. Which line is wrong?

A student's program — which line goes wrong?

Computer Science · Your turn

Build it, then use the call four ways

Finish this program. area(length, width) must work out a rectangle's area from its parameters and send it back. cost_of(square_metres) returns the cost of carpet at 10 per square metre. Then the main program uses a call to area in four different places.

  1. FUNCTION area(length, width)Data comes in through the two parameters.
  2. missing step
Which line is step 2?

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

1Function: a value comes back. Procedure: nothing comes back.
2The first RETURN that runs ends the subroutine. Nothing after it runs.
3The value goes back to the call site, and the call becomes that value.
4Catch it or lose it: store the value or use it straight away.
5Parameters in, return value out, so the calling code doesn't rely on global variables.

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?
A named, self-contained block of code that can be called from elsewhere in the program.
What's the difference between a function and a procedure?
A function returns a value. A procedure doesn't. (These are the usual names; go by whether a value comes back.)
What is a return value?
The value a subroutine sends back to the part of the program that called it, when it finishes.
What two things does a return statement do?
It ends the subroutine, and it passes the return value back to the point where the subroutine was called.
A return statement runs halfway through a function. What happens to the lines after it?
They don't run. The subroutine has already ended.
Where does a returned value go?
Back to the call site, the exact place the subroutine was called from. The call is replaced by that value.
What happens to a returned value if the calling code doesn't store or use it?
It's lost. It has no effect on the rest of the program.
Name four places you can use a call to a function that returns a value.
Assigned to a variable, inside an expression, in a condition, and as an argument to another subroutine.
How do parameters and a return value work together?
Parameters pass data into the subroutine and the return value passes the result out, so the calling code doesn't need to rely on global variables.
Does RETURN display a value on the screen?
No. RETURN sends the value back to the calling code. Only an output statement displays it.
What is an argument?
A value given to a subroutine when it's called. In ticket_cost(2, 3), the arguments are 2 and 3, and they go into the parameters.
Can a function return different values each time it's called?
Yes. The same code with different arguments can send back a different value, e.g. ticket_cost(2, 3) returns 31 but ticket_cost(1, 0) returns 8.

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 posted

More AQA GCSE Computer Science topics

See the full AQA Computer Science curriculum →

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.