Calling Procedures
Introduced| English | Meaning |
|---|---|
| reusable/riːˈjuːzəbl/ | reusable |
| procedure/prəˈsiːdʒə/ | A named sequence of instructions that performs a task when called. |
| call/kɔːl/ | call |
| method/ˈmeθəd/ | A defined way of performing a task or investigation; in programming, a function associated with a class or object. |
| arguments/ˈɑːɡjuːmənts/ | Values or references supplied to a function or procedure when it is called. |
| parameters/pəˈræmɪtəz/ | Named inputs in a function or procedure definition that receive argument values when it is called. |
| return value/rɪˈtɜːn ˈvæljuː/ | return value |
| implementation/ˌɪmplɪmənˈteɪʃn/ | The process of turning a design or algorithm into a working system or program. |
| abstraction/əbˈstrækʃn/ | Representing essential features while leaving out unnecessary detail. |
Reusable blocks of code
- A procedure 过程, also called a function or method 方法, is a named block of reusable 可重用 code.
- You write it once and use it many times.
- It gives a job a name, so you can invoke that job whenever you need it.
- This is the heart of "don't repeat yourself".
A procedure (function/method) is:
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Write it once, call it many times.
To run a procedure's instructions from elsewhere, you ______ it by name.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
After the call finishes, the program continues where it left off.
Calling a procedure
- To run a procedure from elsewhere, you call 调用 it by name.
- When the call finishes, the program continues from where it left off.
- So a call is like a detour: go do the job, then come back.
- The same procedure can be called from many places.

Arguments 实参 are passed in, the body runs, and RETURN sends a value back
How a procedure call works
A call jumps to the procedure with its arguments, runs the body, returns a value, and the program continues where it left off.
Match each term in area(4, 5) to its meaning.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Arguments are the actual values; parameters are the named slots.
In total ← area(4, 5), what does area give back?
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The returned result is stored for later use.
Arguments, parameters, return
- Procedures can take inputs: you pass arguments into a procedure through its parameters 形参.
area(length, width)called asarea(4, 5)receives 4 and 5.- A procedure can also give back a return value 返回值 — a result you use later.
- For example
total ← area(4, 5)stores the returned value.
If square(n) returns n × n, what does square(square(3)) return?
Difficulty 2/5 · 140 coins + a small bonus on first completion today
square(3) = 9, then square(9) = 81.
To call square(3), you must know exactly how it works inside.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
False. Procedural abstraction means you only need to know what the procedure does, not how it is implemented.
Hiding implementation
- Procedures support abstraction 抽象 by hiding implementation 实现 detail from the caller.
- You only need to know what a procedure does, not how it works inside.
square(n) returns n × n. a ← square(3) stores 9. b ← square(a) stores 81, because square(9) is 81. The caller never sees the multiplication inside — it just uses the return value.
A procedure (a function or method) is reusable code you call by name; the program continues after it returns. You pass arguments into its parameters and can use its return value. Procedures give abstraction — the caller knows what it does, not the implementation.