6m left·0%
Reading Time: 6 min
Last Updated: March 10, 2026
Main Ideas: 5
Reading Time: 6 min
Last Updated: March 10, 2026
Main Ideas: 5

Topic 3.12 Notes – Calling Procedures

Verified for 2027 AP® Computer Science Principles Exam
Read aloud
You’ll need to recognize how procedures are defined, how arguments are passed to parameters, and how control moves through the program during a call. This shows up constantly in code-tracing questions.

What a Procedure Is

A procedure is a named group of programming instructions that performs a specific task. Other languages might call it a function or method, but on the AP exam, you’ll see procedure.

Why we use them:

  • Break big problems into smaller pieces
  • Reuse code instead of rewriting it
  • Make programs easier to test and manage

In AP pseudocode (from the reference sheet), a procedure looks like this:

PROCEDURE calculateTotal(price, tax)
{
   total ← price + tax
   RETURN(total)
}

Key parts:

  • calculateTotal → procedure name
  • price, tax → parameters (inputs)
  • Body inside { } → runs when called
  • RETURN(total) → sends a value back

Procedures can:

  • Have parameters or none
  • Return a value or not

Understanding that flexibility matters when you trace code.

Parameters, Arguments, and Return Values

Parameters vs Arguments

This distinction shows up in tricky multiple-choice questions.

  • Parameter = variable listed in the procedure definition
  • Argument = actual value passed in during the call

If we call:

result ← calculateTotal(20, 5)
  • 20 and 5 are arguments
  • price becomes 20
  • tax becomes 5

Arguments are assigned in order:

  • First argument → first parameter
  • Second argument → second parameter

If the numbers don’t match, the call is invalid.

Procedures That Return a Value

A procedure uses:

RETURN(expression)

Two things happen immediately:

  1. The value of the expression is sent back.
  2. The procedure stops running.

Example:

PROCEDURE triple(n)
{
   RETURN(n * 3)
}

Call:

x ← triple(4)

Now x stores 12.

From the reference sheet, this format is important:

result ← procName(arg1, arg2)

That means the returned value is assigned to result.

If you see code after RETURN, ignore it. It never runs. The AP loves testing that detail.

Procedures That Do Not Return a Value

Some procedures just do something instead of returning a value.

Example:

PROCEDURE announce(message)
{
   DISPLAY(message)
}

Call:

announce("Hello")

This prints output, but you would not assign it to a variable.

If you tried:

x ← announce("Hi")

x would not get a meaningful value because nothing is returned.

Built-In Procedures You Must Know

From the reference sheet:

  • DISPLAY(expression)
    • Outputs the value followed by a space.
  • INPUT()
    • Accepts user input
    • Returns the value entered
    • Usually written as:
      response ← INPUT()

Remember that INPUT() returns a value. DISPLAY() does not.

How Procedure Calls Affect Program Flow

Programs normally run top to bottom.

When a procedure is called, execution temporarily jumps elsewhere.

Here’s the flow visually. The left side shows the main program, and the right side shows the separate Cook procedure that gets called:

Study guide illustration

Main routine calling a separate procedure

Notice how control moves from the main flow into Cook, runs through its steps and decision, then returns to the main program.

What actually happens step by step:

  1. The program reaches a procedure call.
  2. It pauses the current line.
  3. Arguments are assigned to parameters.
  4. The procedure body executes.
  5. When the last statement runs, or a RETURN executes, control goes back.
  6. Execution resumes immediately after the call.

Students often think it restarts the program or skips ahead. It doesn’t. It returns to the next line.

Determining the Result of a Procedure Call

This is where most test questions live.

When tracing code:

  1. Plug argument values into parameters.
  2. Run the procedure logic.
  3. Determine the returned value (if any).
  4. Replace the call with that value.
  5. Continue evaluating the original expression.

Example pattern:

a ← 2
b ← triple(a) + 5
  • Evaluate triple(a) first.
  • Replace with returned value.
  • Then add 5.

Nested calls evaluate inside first.

If a procedure only uses DISPLAY, your job is to determine what prints, not what gets stored.

Why This Matters

Procedures let programmers reuse tested code and generalize solutions using parameters. On assessments, you’ll either:

  • Write a correct procedure call, or
  • Trace one and determine its output or returned value

Most mistakes happen when students lose track of parameter substitution or forget that RETURN ends execution immediately.

Key Takeaways

A procedure call temporarily interrupts sequential execution and always returns to the next line after the call.
Parameters are variables in the definition; arguments are the actual values passed in.
Arguments are assigned to parameters strictly by position.
RETURN(expression) both sends back a value and immediately stops the procedure.
DISPLAY() produces output but does not return a value.
INPUT() returns a value and must usually be assigned to a variable.
When tracing, evaluate procedure calls completely before finishing the surrounding expression.

AP® is a trademark registered by the College Board, which is not affiliated with, and does not endorse this website.

Notes

1 credit used · 5/5 remaining