← IGCSE Computer Science Paper 2

Comments above a subroutine

Starts a comment. Put one on the line before a procedure or function to say what it does and what its parameters are. The computer ignores comments.

Understanding Comments above a subroutine in IGCSE Computer Science Paper 2

What it does: The // comment sits directly above the PROCEDURE line and states its purpose. Everything after // on the line is a comment, so it is ignored when the program runs. Comments are only for people reading the code. They never run and never print. A useful comment is specific. It says what the subroutine does and what the parameter is for. Comments must begin with // so that the computer ignores them.

Common mistakes: A short end-of-line comment must start with //. A single / is not a comment, so the computer tries to run 'doubled value' as code. It should be: OUTPUT D // doubled value. The line before the function has no // at the start, so the computer treats the words as code and gives an error. It should be: // Returns a random number.

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
Which line is a correct comment in Cambridge IGCSE pseudocode?
// Calculates the area of a circle# Calculates the area of a circle
Matches
Calculates the area of a rectangle FUNCTION Area(w : INTEGER, h : INTEGER) RETURNS INTEGER
↓
The comment has no // at the start, so the computer treats it as code and reports an error. It should be // Calculates the area of a rectangle.
Applying
Meanings
Term
//
Meaning
Starts a comment. Put one on the line before a procedure or function to say what it does and what its parameters are. The computer ignores comments.
Practice
// Adds two whole numbers and returns the total
Testing
Gaps
Shows a welcome message. No parameters.
Check Answer
Spots
3 D ← N * 2
4 OUTPUT D / doubled value

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

The 'Bear' badge — Forest Guardian, 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. Which line is a correct comment in Cambridge IGCSE pseudocode?
A. // Calculates the area of a circle ✓
B. # Calculates the area of a circle
Cambridge pseudocode comments start with //. The computer ignores everything after // on that line.
2. Where is the best place to put a comment that explains what a procedure does?
A. After ENDPROCEDURE at the end
B. On the line before PROCEDURE ✓
A comment above the subroutine tells the reader its purpose before they read the code.
3. What does the computer do with a // comment when the program runs?
A. Ignores it ✓
B. Displays it with OUTPUT
Comments are only for people reading the code. They never run and never print.
4. A comment above FUNCTION Square(Num : INTEGER) RETURNS INTEGER should mention...
A. What it does and what Num is ✓
B. Only the name of the programmer
A good comment states the purpose of the subroutine and describes its parameters.
5. Which comment is at the correct indentation for code that is not indented?
A. // Show a greeting PROCEDURE Greet()
B. // Show a greeting PROCEDURE Greet() ✓
A comment should line up with the code it describes. Here the PROCEDURE line has no indent, so the comment has none either.

Match the Pairs

// Calculates the area of a rectangle → A comment placed on the line before a function that states its purpose
// width and height are both INTEGER → A comment that states the parameters of the subroutine below it
A comment is written on the line before the procedure and explains what it does → // Displays a greeting for the name given PROCEDURE Greet(name : STRING)
A short end-of-line comment can explain one line of code, and the computer ignores it → total ← total + 1 // add one to the count
Calculates the area of a rectangle FUNCTION Area(w : INTEGER, h : INTEGER) RETURNS INTEGER → The comment has no // at the start, so the computer treats it as code and reports an error. It should be // Calculates the area of a rectangle.
PROCEDURE ShowScore(score : INTEGER) // Displays the score → The comment is placed after the procedure header instead of on the line before it. It should be written above the PROCEDURE line.

Key Term

//
Starts a comment. Put one on the line before a procedure or function to say what it does and what its parameters are. The computer ignores comments.

Fill in the Blanks

1. // Shows a welcome message. No parameters. PROCEDURE ShowMessage() OUTPUT "Welcome"
Hint: Type the symbol that starts a comment line, which the computer ignores.
2. // Returns N multiplied by 2 FUNCTION Double(N : INTEGER) RETURNS INTEGER RETURN N * 2
Hint: Type the parameter name that the comment above describes.
3. Total ← Price * Qty // cost of all items
Hint: Type the symbol that starts a short end-of-line comment.
4. // Shows Name on the screen. Parameter: Name PROCEDURE ShowName(Name : STRING) OUTPUT Name
Hint: Type the keyword that begins a subroutine which does not return a value.
5. // Purpose: add tax to Price FUNCTION AddTax(Price : REAL) RETURNS REAL RETURN Price * 1.2
Hint: Type the keyword that sends the result back to the code that called the function.

Spot the Error

Question 1
A // Shows N doubled
B PROCEDURE Show(N : INTEGER)
C D ← N * 2
D OUTPUT D / doubled value
E ENDPROCEDURE
Line D — A short end-of-line comment must start with //. A single / is not a comment, so the computer tries to run 'doubled value' as code. It should be: OUTPUT D // doubled value.
Question 2
A OUTPUT "Start"
B Returns a random number
C FUNCTION Roll() RETURNS REAL
D RETURN RANDOM()
E ENDFUNCTION
Line B — The line before the function has no // at the start, so the computer treats the words as code and gives an error. It should be: // Returns a random number.
Question 3
A DECLARE Score : INTEGER
B Score ← 0
C // Takes 1 from the score
D PROCEDURE AddOne()
E Score ← Score + 1
F ENDPROCEDURE
Line C — The comment above a subroutine must state what it really does. AddOne adds 1 to Score, it does not take 1 away. It should be: // Adds 1 to the score.
Question 4
A Total ← 0
B -- Shows the total
C PROCEDURE ShowTotal()
D OUTPUT Total
E ENDPROCEDURE
Line B — Comments in IGCSE pseudocode start with //, not --. It should be: // Shows the total.
Question 5
A // Shows the total price
B // A: price of one item
C // B: number of items
D PROCEDURE Cost(A : INTEGER)
E OUTPUT A * B
F ENDPROCEDURE
Line D — The comments say the procedure has two parameters, A and B, but the header only has A. The header must match the comments and the body: PROCEDURE Cost(A, B : INTEGER).

Student with a class code? Join your class →