📁 Topic 2 · 2.6 Sub-programs
2.6 Procedures, functions and parameters
Edexcel 4CP0 · iGCSE Computer Science · ~13 min read
Notes
──
Video
──
Slides
──
Worksheet
──
Quiz

What are Sub-programs?

A sub-program is a named block of code that performs a specific task. Instead of writing the same code multiple times, you define it once and call it whenever needed. Sub-programs make programs easier to read, test, and maintain.

There are two types of sub-program in Edexcel 4CP0: procedures and functions.

Procedures

A procedure performs a task but does not return a value. It uses the keywords PROCEDURE / BEGIN PROCEDURE / END PROCEDURE.

PROCEDURE greet()
BEGIN PROCEDURE
SEND "Welcome to CSZone!" TO DISPLAY
SEND "Good luck with your revision." TO DISPLAY
END PROCEDURE

# Call the procedure
greet()

Procedure with Parameters

Parameters allow data to be passed into a sub-program so it can work with different values each time it is called.

PROCEDURE greetByName(name)
BEGIN PROCEDURE
SEND "Hello, " & name & "!" TO DISPLAY
END PROCEDURE

# Call with different arguments
greetByName("Alice") # outputs: Hello, Alice!
greetByName("Bob") # outputs: Hello, Bob!

Functions

A function performs a task AND returns a value using the RETURN keyword. It uses FUNCTION / BEGIN FUNCTION / END FUNCTION.

FUNCTION square(n)
BEGIN FUNCTION
RETURN n * n
END FUNCTION

// Call and use the returned value
SET result TO square(7)
SEND result TO DISPLAY // outputs 49

SEND square(3) TO DISPLAY // outputs 9

Function with Multiple Parameters

FUNCTION calculateArea(length, width)
BEGIN FUNCTION
RETURN length * width
END FUNCTION

SET area TO calculateArea(10, 5)
SEND "Area = " & area TO DISPLAY # outputs: Area = 50

Procedures vs Functions

FeatureProcedureFunction
Returns a value?NoYes — uses RETURN
SyntaxPROCEDURE / BEGIN PROCEDURE / END PROCEDUREFUNCTION / BEGIN FUNCTION / END FUNCTION
Called howCalled as a statement: greet()Called in an expression: SET x TO square(4)
Best used forPerforming actions (display, write to file)Calculating and returning a result

Benefits of Sub-programs

  • Reusability — write once, call many times; avoids duplicating code
  • Readability — meaningful sub-program names make code easier to understand
  • Easier testing — each sub-program can be tested independently
  • Maintainability — fixing a bug in one place fixes it everywhere the sub-program is called
  • Decomposition — naturally supports breaking a large problem into smaller parts
📝 Exam Tip: The key difference: a function RETURNS a value; a procedure does NOT. If a question asks for a value to be calculated and sent back to the calling code, always use a function with RETURN.
⚠️ Common Mistakes
  • Using a procedure when a function is needed — if the sub-program needs to send a value back, use FUNCTION and RETURN
  • Forgetting BEGIN PROCEDURE / BEGIN FUNCTION keywords — Edexcel pseudocode requires them
  • Confusing parameters (in the definition) with arguments (the actual values passed when calling)
← 2.5 Operators Topic 2 · 2.6 Sub-programs Next: Topic 3 – Data Representation →
🔒
Pro Content
Subscribe to access all 47 Edexcel iGCSE lessons.
£7.99/month
or £59/year