← IGCSE Computer Science Paper 2

Writing relevant and appropriate comments

A good comment explains why a section of code exists or a tricky step, without repeating the code word for word. Put it at the same indentation as the code it describes.

Understanding Writing relevant and appropriate comments in IGCSE Computer Science Paper 2

What it does: The comment lines up with the INPUT line below it, so the reader can see which code it belongs to. It explains the reason for MOD 2 instead of repeating the code word for word. Explaining why the check exists helps the reader. Repeating the condition in words adds nothing. Too many pointless comments clutter the program and hide the useful ones. The first comment gives the purpose of the MOD step. The second is wrong and describes what the line does not do. Comments should summarise the purpose of a section, not duplicate the code line by line. The number -1 has no obvious meaning on its own, so the comment explains why it is used.

Common mistakes: The comment just repeats the code in symbols, so it adds nothing. A good comment gives the purpose, for example // Work out the price with VAT. Cambridge pseudocode comments start with //, not #. Without // the line is not a valid comment. It should be // Check if the student passed.

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 347–357) and word search (Modules 337–357).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which comment is better for the line: Total ← Total + Price
// Add the price of this item to the bill// Total becomes Total plus Price
Matches
// Set Total to 0 Total ← 0
↓
The comment repeats the code word for word and adds no new information. A pointless comment like this just adds clutter.
Applying
Meanings
Term
// explain purpose
Meaning
A good comment explains why a section of code exists or a tricky step, without repeating the code word for word. Put it at the same indentation as the code it describes.
Practice
// Find the final price after a discount
Testing
Gaps
Convert minutes into whole hours
Check Answer
Spots
2INPUT Price
3// Cost = Price * (1 + VAT)

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

The 'Lion's Mane Jellyfish' badge — Set Operator, 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 comment is better for the line: Total ← Total + Price
A. // Add the price of this item to the bill ✓
B. // Total becomes Total plus Price
A good comment explains the purpose of the code. The other comment just repeats the code word for word.
2. Which comment explains WHY, not just what, for: IF Age < 13 THEN
A. // Under 13s need a parent's permission ✓
B. // If Age is less than 13
Explaining why the check exists helps the reader. Repeating the condition in words adds nothing.
3. Where should a comment be placed in this loop? FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
A. At the far left, whatever the code's indentation
B. At the same indentation as the code it describes ✓
Comments follow the layout of the code they describe, so they line up with it and are easy to read.
4. A program has 10 lines. Which commenting approach is better?
A. Put a comment on every single line, even obvious ones
B. Comment only the sections or tricky steps that need explaining ✓
Too many pointless comments clutter the program and hide the useful ones.
5. Which comment is appropriate for the line: Remainder ← Number MOD 2
A. // Find out if the number is odd or even ✓
B. // Declare a variable called Remainder
The first comment gives the purpose of the MOD step. The second is wrong and describes what the line does not do.

Match the Pairs

// Add 10% service charge to the bill Total ← Bill * 1.1 → A good comment that explains the purpose of the calculation, not just the symbols used
// Stop once the user enters -1 WHILE Score <> -1 → A comment that explains a non-obvious step, in this case the value that ends the loop
A comment should sit at the same indentation as the code it describes → FOR Count ← 1 TO 5 // Ask for one test mark INPUT Mark NEXT Count
A good comment explains why the code does something, not just what it does → // Use MOD 2 to check if the number is even IF Number MOD 2 = 0 THEN
// Set Total to 0 Total ← 0 → The comment repeats the code word for word and adds no new information. A pointless comment like this just adds clutter.
WHILE Lives > 0 // Ask for a guess INPUT Guess ENDWHILE → The comment is not at the same indentation as the code it describes, so it is not clear which code it belongs to.

Key Term

// explain purpose
A good comment explains why a section of code exists or a tricky step, without repeating the code word for word. Put it at the same indentation as the code it describes.

Fill in the Blanks

1. // Convert minutes into whole hours Hours ← Minutes DIV 60
Hint: Type the symbol that starts a comment line in Cambridge pseudocode.
2. IF Age < 0 THEN // Age cannot be negative OUTPUT "Invalid age"
Hint: Type the comment marker. The comment sits at the same indentation as the code it describes.
3. // Total cost including 10% tax TotalCost ← Price * 1.1
Hint: Type the assignment operator that stores the result in the variable.
4. // Pass mark is 40 out of 100 CONSTANT PassMark ← 40
Hint: Type the keyword that declares a fixed value, which the comment explains the purpose of.
5. // Average of three test marks Average ← (Mark1 + Mark2 + Mark3) / 3 OUTPUT Average
Hint: Type the keyword that displays a value to the screen.

Spot the Error

Question 1
A CONSTANT VAT ← 0.2
B INPUT Price
C // Cost = Price * (1 + VAT)
D Cost ← Price * (1 + VAT)
Line C — The comment just repeats the code in symbols, so it adds nothing. A good comment gives the purpose, for example // Work out the price with VAT.
Question 2
A DECLARE Score : INTEGER
B INPUT Score
C # Check if the student passed
D IF Score >= 50
E THEN
F OUTPUT "Pass"
Line C — Cambridge pseudocode comments start with //, not #. Without // the line is not a valid comment. It should be // Check if the student passed.
Question 3
A FOR Count ← 1 TO 10
B INPUT Mark
C // Add Mark to Total
D Total ← Total + Mark
E NEXT Count
Line C — This comment only repeats the code below it word for word, so it explains nothing. A good comment gives the purpose: // Keep a running total.
Question 4
A Total ← 0
B FOR Count ← 1 TO 5
C INPUT Mark
D // Reset the counter
E Total ← Total + Mark
F NEXT Count
Line D — The comment is misleading because the next line adds to Total and does not reset anything. A comment must match what the code does: // Add mark to the total.
Question 5
A INPUT Minutes
B Hours ← Minutes DIV 60
C Left ← Minutes MOD 60
D // OUTPUT the variables
E OUTPUT Hours, Left
Line D — This comment is vague and just names the command, so it explains no purpose. It should say why, for example // Show hours and minutes.

Student with a class code? Join your class →