Skip to main content
AP CSP course

C40 · Topic 3.12 · 40 minutes · AAP-3.A

Tracing returned values

By the end you can:

  • Use a returned value in a caller expression.
  • Explain how RETURN ends a call.
  • Distinguish return from display.

Before this lesson: topics 3.1, 3.6.

Parameter
A name in a procedure definition that receives an argument value.
Argument
A value supplied in a particular procedure call.

Understand

RETURN supplies a value to the caller and ends that procedure call. The caller can store it, compare it or use it in a larger expression. A later statement in the same procedure body is not reached after an unconditional return, so return placement is part of the algorithm’s behaviour.

DISPLAY presents information but is not interchangeable with returning a value for another computation. Explain the complete path from argument bindings through the returned value to the caller’s later calculation. If the contract returns nothing, do not invent a numerical result just because a number appeared on screen.

Worked example

The caller computes total←quote(5,2,3)+1.

  1. The call returns 11 after evaluating its own parameters and body.
  2. The caller adds 1 and stores 12 in total.
  3. Replacing RETURN with DISPLAY would show 11 but would not supply a returned number for this expression.

Explore each concept

Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.

  • Argument binding and local calls
  • RETURN ends the call
  • DISPLAY is not a returned value
Open this example on its own

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to explore: Call, return, display and resume
  1. Argument (0–10)3Waiting
  2. Procedure bodyreturnWaiting

Ready to explore: Call, return, display and resume

Why: Change an input, predict the first effect, then advance one step.

Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.

Step through and experiment

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 15Waiting
  2. Input 22Waiting
  3. Input 33Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Change one input, predict the difference, then reset and compare.

Check a misconception

Claim: A visible output automatically becomes the call’s returned value.

Presentation and return are different effects with different uses.

Guided practice

Trace x←quote(4,3,2);y←x*2;DISPLAY(y).

Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.

Independent transfer

A procedure returns inside the first loop iteration. What happens to later iterations in that call?

Exit check

When should a caller require a returned result rather than only displayed output?

Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.

Check yourself

  1. Question 1 of 2A call returns 9 and the caller adds 4. What is stored?

    Select one answer.

  2. Question 2 of 2Which TWO statements are correct?

    Select exactly two answers (0 of 2 selected).

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring