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 * 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 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.

1 / 12

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.

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

Two kinds of subroutine

FunctionvsProcedure

ticket_cost sent a value back. Not every subroutine does.

Focus

What comes back

Function

A value, sent back by a return statement

Procedure

No value. It does its job, such as displaying something, and finishes.

The insight

This is the difference people mix up. It isn't about doing maths: a procedure can calculate too. It's about whether a value comes back. Function and procedure are the usual names, so read what a question calls them.

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, wherever a value of that type is expected

Procedure

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

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?

Computer Science · Programming

Where does a returned value actually go?

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

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

Computer Science · Programming

The value that went missing

This program should output the price after a £5 discount, which is 35. It outputs 40 instead. The function itself is fine: apply_discount(40) really does return 35. Which line is wrong?

A program with one bug — which line goes wrong?

Computer Science · Programming

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 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

1A function sends a value back; a procedure doesn't. Those are the usual names.
2The first return statement that runs ends the subroutine. Later lines in it don't run.
3The value goes back to the call site, and the call can be used wherever a value of that type is expected.
4If the calling code ignores the returned value, it's lost.
5Parameters in and a return value out mean the calling code needn't rely on global variables.
6To trace a call, ask: what does this line become once the call has returned?

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?
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 sends a value back; a procedure doesn't. Those are the usual names for the two kinds of subroutine.
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. Nothing saves it automatically.
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 in and the return value passes the result out, so the calling code needn't rely on global variables.
Does a return statement display a value on the screen?
No. It sends the value back to the calling code. Only an output statement displays it.
What is an argument?
A value handed to a subroutine when it is called. It lands in the matching parameter.

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 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.