← IGCSE Computer Science Paper 2

Control passing to a subroutine and back

Control passes to the subroutine, which runs its statements in order. After its last statement, control returns to the line that follows the call.

Understanding Control passing to a subroutine and back in IGCSE Computer Science Paper 2

What it does: Start calls ShowMenu. When ShowMenu finishes, control returns to Start and OUTPUT "Done" runs next. Control returns to the line after the call, so the main program carries on from there.

Common mistakes: A call needs brackets after the subroutine name. It should be CALL ShowMenu() so control passes to ShowMenu and then returns to the next line. RUN is not the keyword for calling a procedure. It should be CALL Menu(). After Menu finishes, control returns to OUTPUT "End".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 399–408) and word search (Modules 399–418).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
After a subroutine finishes its last statement, where does the program continue?
On the line that follows the callAt the very first line of the program
Matches
CALL ShowMenu() OUTPUT "Menu closed" // Output order: Menu closed, then the menu lines
↓
The statement after the call does not run first. Control passes into ShowMenu, and the next line runs only after ShowMenu ends.
Applying
Meanings
Term
CALL ShowMenu()
Meaning
Control passes to the subroutine, which runs its statements in order. After its last statement, control returns to the line that follows the call.
Practice
PROCEDURE ShowMenu()
Testing
Gaps
ShowMenu()
Check Answer
Spots
1OUTPUT "Start"
2CALL ShowMenu

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Woodland Hedgehog' badge — Import Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. After a subroutine finishes its last statement, where does the program continue?
A. On the line that follows the call ✓
B. At the very first line of the program
Control returns to the line after the call, so the main program carries on from there.
2. Which statement is true when CALL ShowMenu() runs?
A. The main program skips ShowMenu and carries on
B. Control passes to ShowMenu and its statements run in order ✓
A call hands control to the subroutine. Its statements run in order from the first one.
3. The main program is: 1 OUTPUT "A" / 2 CALL Show() / 3 OUTPUT "C". Show() outputs "B". What is the output order?
A. A, C, B
B. A, B, C ✓
Line 1 outputs A. The call runs Show(), which outputs B. Control then returns to line 3, which outputs C.
4. Which line runs straight after Greet() finishes? 1 CALL Greet() / 2 OUTPUT "Done"
A. Line 2, OUTPUT "Done" ✓
B. Line 1, CALL Greet() again
Control returns to the line that follows the call, which is line 2. The call is not repeated.
5. Procedure A contains the statement CALL B(). When B finishes, where does control go?
A. Back to the line in A after CALL B() ✓
B. Straight back to the main program
Control returns to whoever made the call. Since A called B, it goes back into A, just after CALL B().

Match the Pairs

CALL ShowMenu() → Control passes to ShowMenu, which runs its statements in order, then control returns to the next line
ENDPROCEDURE → The last line of the procedure: control returns to the line after the CALL
One procedure can call another, and control returns to the first procedure when the second one ends → PROCEDURE Start() CALL ShowMenu() OUTPUT "Done" ENDPROCEDURE
After a subroutine ends, the program continues with the line that follows the call → CALL ShowMenu() OUTPUT "Menu closed"
CALL ShowMenu() OUTPUT "Menu closed" // Output order: Menu closed, then the menu lines → The statement after the call does not run first. Control passes into ShowMenu, and the next line runs only after ShowMenu ends.
// After ENDPROCEDURE, the program stops CALL ShowMenu() OUTPUT "Menu closed" → The program does not stop at ENDPROCEDURE. Control returns to the line after the CALL and the program carries on.

Key Term

CALL ShowMenu()
Control passes to the subroutine, which runs its statements in order. After its last statement, control returns to the line that follows the call.

Fill in the Blanks

1. CALL ShowMenu() OUTPUT "Done"
Hint: Type the keyword that passes control to a procedure.
2. PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Hint: Type the keyword that ends the procedure, where control goes back to the caller.
3. PROCEDURE Start() CALL Setup() ENDPROCEDURE
Hint: Type the keyword one procedure uses to pass control to another procedure.
4. OUTPUT "Start" CALL Show() OUTPUT "End"
Hint: Type the statement keyword on the line that runs after control returns from the call.
5. PROCEDURE ShowMenu() OUTPUT "Menu" ENDPROCEDURE
Hint: Type the keyword that begins the definition of a procedure that can be called.

Spot the Error

Question 1
A OUTPUT "Start"
B CALL ShowMenu
C OUTPUT "End"
Line B — A call needs brackets after the subroutine name. It should be CALL ShowMenu() so control passes to ShowMenu and then returns to the next line.
Question 2
A OUTPUT "Start"
B RUN Menu()
C OUTPUT "End"
Line B — RUN is not the keyword for calling a procedure. It should be CALL Menu(). After Menu finishes, control returns to OUTPUT "End".
Question 3
A PROCEDURE ShowMenu()
B OUTPUT "1 Play"
C ENDPROCEDURE
D CALL ShowMeni()
Line D — The name in the call must match the procedure name exactly. ShowMeni does not exist, so control cannot pass to ShowMenu. It should be CALL ShowMenu().
Question 4
A PROCEDURE Hello()
B OUTPUT "Hi"
C ENDPROCEDURE
D OUTPUT Hello()
E OUTPUT "Done"
Line D — Hello is a procedure, so it does not give back a value to output. It must be called with CALL Hello(). Then control returns to OUTPUT "Done".
Question 5
A PROCEDURE Inner()
B OUTPUT "Inner"
C ENDFUNCTION
D PROCEDURE Outer()
E CALL Inner()
F ENDPROCEDURE
Line C — A procedure must finish with ENDPROCEDURE, not ENDFUNCTION. ENDPROCEDURE marks the end where control returns to the line after the call.

Student with a class code? Join your class →