← IGCSE Computer Science Paper 2

Indentation and comments in pseudocode

Starts a comment in Cambridge pseudocode. Statements inside a loop or IF are indented four spaces, and ELSE lines up with its IF, so the structure is easy to read.

Understanding Indentation and comments in pseudocode in IGCSE Computer Science Paper 2

What it does: OUTPUT Count is the loop body and is indented four spaces, while FOR and NEXT stay at the left. Cambridge pseudocode starts a comment with //. The # symbol is used for comments in Python, not in Cambridge pseudocode. A comment needs two slashes, //. A single / is not a comment, so the line would cause an error. Everything after // is a comment. In the wrong answer the // comes first, so the assignment is turned into a comment and never runs. Indentation and comments help people read the algorithm. Comments are ignored when the algorithm is followed.

Common mistakes: A comment after a statement starts with //, not #. The line should be ' total <- total + n // add'. Cambridge pseudocode comments start with //. The /* ... */ style belongs to other languages. The line should be ' // count down by one'.

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 358–368) and word search (Modules 358–378).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which symbol starts a comment in Cambridge pseudocode?
//#
Matches
FOR Count <- 1 TO 3 OUTPUT Count NEXT Count
↓
The loop body is not indented. OUTPUT Count should be indented four spaces so it is clearly inside the loop.
Applying
Meanings
Term
//
Meaning
Starts a comment in Cambridge pseudocode. Statements inside a loop or IF are indented four spaces, and ELSE lines up with its IF, so the structure is easy to read.
Practice
// Count the passes
Testing
Gaps
Ask the user for a name
Check Answer
Spots
3 INPUT n
4 total <- total + n # add

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

The 'Oryx' badge — Desert Navigator, 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 symbol starts a comment in Cambridge pseudocode?
A. // ✓
B. #
Cambridge pseudocode starts a comment with //. The # symbol is used for comments in Python, not in Cambridge pseudocode.
2. How far are the statements inside a FOR loop indented?
A. Not indented, lined up with FOR
B. Four spaces in from the FOR line ✓
The body of a loop is indented four spaces. This shows which statements are repeated.
3. Where should ELSE be placed in an IF statement?
A. Lined up with its IF ✓
B. Indented four spaces under the IF
ELSE lines up with its IF. Only the statements inside each branch are indented four spaces.
4. Which is a correct comment on its own line?
A. / Ask the user for a mark
B. // Ask the user for a mark ✓
A comment needs two slashes, //. A single / is not a comment, so the line would cause an error.
5. Which line has a correct comment after a statement?
A. Count <- Count + 1 // add one to count ✓
B. // Count <- Count + 1 add one to count
Everything after // is a comment. In the wrong answer the // comes first, so the assignment is turned into a comment and never runs.

Match the Pairs

// Add the mark to the total → A comment on its own line. The computer ignores it; it explains the code to a human reader.
Total <- Total + Mark // running total → A comment after a statement. The assignment still runs and everything after // is ignored.
The body of a FOR loop is indented four spaces so the repeated statements stand out → FOR Count <- 1 TO 5 OUTPUT Count NEXT Count
ELSE lines up with its IF, and the statements in each branch are indented four spaces → IF Mark >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
FOR Count <- 1 TO 3 OUTPUT Count NEXT Count → The loop body is not indented. OUTPUT Count should be indented four spaces so it is clearly inside the loop.
IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF → ELSE is indented. It should line up with its IF at the left edge.

Key Term

//
Starts a comment in Cambridge pseudocode. Statements inside a loop or IF are indented four spaces, and ELSE lines up with its IF, so the structure is easy to read.

Fill in the Blanks

1. // Ask the user for a name INPUT Name
Hint: Type the symbol that starts a comment line in Cambridge pseudocode.
2. FOR Count <- 1 TO 5 OUTPUT Count // show the number NEXT Count
Hint: Type the symbol that starts a comment placed after a statement.
3. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Hint: Type the indentation (spaces) for a statement inside the IF.
4. WHILE Num > 0 DO Num <- Num - 1 ENDWHILE
Hint: Type the keyword that closes the loop, lined up with its WHILE.
5. FOR Count <- 1 TO 3 // Print the count OUTPUT Count
Hint: Type the symbol that starts a comment on its own line inside the loop body.

Spot the Error

Question 1
A total <- 0
B FOR i <- 1 TO 5
C INPUT n
D total <- total + n # add
E NEXT i
Line D — A comment after a statement starts with //, not #. The line should be ' total <- total + n // add'.
Question 2
A WHILE n > 0 DO
B /* count down by one */
C n <- n - 1
D ENDWHILE
Line B — Cambridge pseudocode comments start with //. The /* ... */ style belongs to other languages. The line should be ' // count down by one'.
Question 3
A IF age >= 16 THEN
B OUTPUT "Adult"
C ELSE THEN
D OUTPUT "Child"
E ENDIF
Line C — ELSE stands on its own line, lined up with its IF. Only IF takes THEN. The line should be 'ELSE'.
Question 4
A REM Add up five marks
B total <- 0
C FOR i <- 1 TO 5
D total <- total + i
E NEXT i
Line A — Cambridge pseudocode starts a comment with //, not REM. The line should be '// Add up five marks'.
Question 5
A IF score > 50 THEN
B / score is a pass
C OUTPUT "Pass"
D ENDIF
Line B — A comment needs two slashes, //. A single / would be read as code. The line should be ' // score is a pass'.

Student with a class code? Join your class →