← IGCSE Computer Science Paper 2

Reuse: write once, call many times

Calls the Line procedure written once, so the same code is reused many times with different parameters instead of being repeated in the program.

Understanding Reuse: write once, call many times in IGCSE Computer Science Paper 2

What it does: Both calls use the one Line procedure, and only the parameter value changes, so no loop is copied. A subroutine is written once and called many times, so the same code is not repeated. Reuse is the main point of a subroutine: define it once, then call it whenever it is needed. Calling a subroutine takes one line, so the program is shorter than with repeated loops. A CALL statement runs a subroutine that already exists, so the program does not need its own copy of the code. The header is written one time and the parameter Length lets every call pass in its own value.

Common mistakes: A procedure is run with the CALL keyword. The line should be CALL Line(3), so the same Line procedure is reused again. The loop ignores the parameter and always repeats 5 times, so reuse with different values would not work. It should be FOR i ← 1 TO N.

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 429–438) and word search (Modules 419–438).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A program needs to draw a line of stars in five different places. What is the best way to do this?
Write one Line procedure and CALL it five timesCopy and paste the same loop five times
Matches
FOR i ← 1 TO 5 OUTPUT "*" NEXT i FOR i ← 1 TO 5 OUTPUT "*" NEXT i
↓
The same loop is copied out twice instead of being written once in a procedure and called twice. This wastes typing and makes copy errors more likely.
Applying
Meanings
Term
CALL Line(5)
Meaning
Calls the Line procedure written once, so the same code is reused many times with different parameters instead of being repeated in the program.
Practice
PROCEDURE Line(Count : INTEGER)
Testing
Gaps
Line(5)
Check Answer
Spots
2CALL Line(8)
3Line(3)

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

The 'Moray Eel' badge — Lurking Debugger, 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. A program needs to draw a line of stars in five different places. What is the best way to do this?
A. Write one Line procedure and CALL it five times ✓
B. Copy and paste the same loop five times
A subroutine is written once and called many times, so the same code is not repeated.
2. Which statement about a subroutine is true?
A. It must be written again each time it is used
B. It is written once and can be called from many places ✓
Reuse is the main point of a subroutine: define it once, then call it whenever it is needed.
3. Which pair of calls reuses the same procedure to print lines of different lengths?
A. CALL Line(5) and CALL Line(8) ✓
B. CALL Line(5) and CALL Stars(8)
The same procedure Line is called twice, with a different parameter value each time. Stars is a different procedure.
4. What changes between CALL Line(3) and CALL Line(10)?
A. The value passed in, so the line is a different length ✓
B. The procedure code has to be rewritten
The procedure code stays the same. Only the value passed in changes, which changes what the procedure does.
5. What is the effect of using one Line procedure instead of repeating the loop code everywhere?
A. The program is longer
B. The program is shorter ✓
Calling a subroutine takes one line, so the program is shorter than with repeated loops.

Match the Pairs

CALL Line(5) → Calls the Line procedure with the value 5, reusing code that was written once instead of repeating a loop
PROCEDURE Line(Length : INTEGER) → Defines the reusable code once, with a parameter so each call can use a different value
Reuse with different parameters: the same procedure draws a short line and then a long line → CALL Line(3) CALL Line(10)
A subroutine written once is called from many places, so the program is shorter than repeating the loop → CALL Line(4) CALL Line(4) CALL Line(4)
FOR i ← 1 TO 5 OUTPUT "*" NEXT i FOR i ← 1 TO 5 OUTPUT "*" NEXT i → The same loop is copied out twice instead of being written once in a procedure and called twice. This wastes typing and makes copy errors more likely.
PROCEDURE Line() FOR i ← 1 TO 5 OUTPUT "*" NEXT i ENDPROCEDURE → The length 5 is fixed inside the procedure and there is no parameter, so every call draws the same line. The procedure cannot be reused for different lengths.

Key Term

CALL Line(5)
Calls the Line procedure written once, so the same code is reused many times with different parameters instead of being repeated in the program.

Fill in the Blanks

1. CALL Line(5)
Hint: Type the keyword used to run a procedure that has already been written.
2. CALL Line(5) CALL Line(8) CALL Line(3)
Hint: Type the name of the procedure that is being reused on every call.
3. Width ← 7 CALL Line(Width)
Hint: Type the variable whose value is passed as the parameter.
4. PROCEDURE Line(Count : INTEGER) FOR Index ← 1 TO Count OUTPUT "*"
Hint: Type the parameter name that sets how many times the loop repeats.
5. NEXT Index ENDPROCEDURE CALL Line(6)
Hint: Type the keyword that closes the procedure definition.

Spot the Error

Question 1
A CALL Line(5)
B CALL Line(8)
C Line(3)
Line C — A procedure is run with the CALL keyword. The line should be CALL Line(3), so the same Line procedure is reused again.
Question 2
A PROCEDURE Line(N : INTEGER)
B FOR i ← 1 TO 5
C OUTPUT "*"
D NEXT i
E ENDPROCEDURE
Line B — The loop ignores the parameter and always repeats 5 times, so reuse with different values would not work. It should be FOR i ← 1 TO N.
Question 3
A FUNCTION Line(N : INTEGER)
B FOR i ← 1 TO N
C OUTPUT "*"
D NEXT i
E ENDPROCEDURE
Line A — Line only outputs stars and returns no value, so it is a procedure. It must start with PROCEDURE to match ENDPROCEDURE.
Question 4
A CALL Line(10)
B CALL Line("4")
C OUTPUT "Done"
Line B — The parameter N is an INTEGER, so the argument must be the number 4, not the string "4". It should be CALL Line(4).
Question 5
A OUTPUT "Menu"
B CALL Line(20)
C OUTPUT "1 Play"
D CALL Line 20
Line D — The argument must be inside brackets when calling a procedure. It should be CALL Line(20), reusing the same procedure.

Student with a class code? Join your class →