← IGCSE Computer Science Paper 2

Indentation in pseudocode

Statements inside a loop or IF are moved in by four spaces, but THEN and ELSE are moved in by only two. Nested statements keep indenting, which makes the structure easy to read.

Understanding Indentation in pseudocode in IGCSE Computer Science Paper 2

What it does: The IF sits four spaces inside the WHILE, its THEN is two more, and the OUTPUT is indented again, so the nesting is easy to see. Indentation does not change the logic of the algorithm. It makes the structure easy to read. Closing keywords such as ENDIF, ENDWHILE and NEXT line up with the statement they close.

Common mistakes: The closing keyword lines up with the FOR line at the left margin, and a FOR loop is closed with NEXT Count. ENDWHILE closes a WHILE loop. It should be 'NEXT Count'. The WHILE header ends with DO, and the loop body is then indented by four spaces underneath it. The header should be 'WHILE Score < 10 DO'.

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 17–26) and word search (Modules 1–26).

Take this worksheet further — free with Cloodit

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

Learning
Duo
How far are statements inside a FOR loop body indented in Cambridge pseudocode?
Four spacesTwo spaces
Matches
FOR Count ← 1 TO 3 OUTPUT Count NEXT Count
↓
The loop body is not indented. OUTPUT Count should be moved in by four spaces.
Applying
Meanings
Term
indentation
Meaning
Statements inside a loop or IF are moved in by four spaces, but THEN and ELSE are moved in by only two. Nested statements keep indenting, which makes the structure easy to read.
Practice
FOR Count ← 1 TO 3
Testing
Gaps
OUTPUT
Check Answer
Spots
2 OUTPUT Count * 2
3ENDWHILE

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

The 'Tree Frog' badge — Leap of Logic, 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. How far are statements inside a FOR loop body indented in Cambridge pseudocode?
A. Two spaces
B. Four spaces ✓
Statements inside a loop body are indented by four spaces. Only THEN and ELSE use two spaces.
2. Which line is indented correctly inside an IF statement? IF Score > 50 THEN OUTPUT "Pass" ENDIF
A. THEN at two spaces, OUTPUT at four spaces ✓
B. THEN at four spaces, OUTPUT at two spaces
THEN and ELSE are indented by two spaces. The statements inside them are indented by four spaces.
3. Which ELSE indentation is correct?
A. ELSE (two spaces) ✓
B. ELSE (four spaces)
ELSE is lined up with THEN, indented by two spaces. The statements under it are indented by four.
4. A WHILE loop contains an IF statement. How should the IF be indented?
A. Four spaces, because it is inside the loop ✓
B. No indent, because IF is a keyword
Any statement inside a loop is indented by four spaces, even if it is another IF.
5. The body of a FOR loop is not indented at all. What is the effect?
A. The loop will not repeat any more
B. The code is harder to read because the structure is not clear ✓
Indentation does not change the logic of the algorithm. It makes the structure easy to read.

Match the Pairs

FOR Count ← 1 TO 3 OUTPUT Count NEXT Count → The statement inside the loop body is indented by four spaces
IF Score > 50 THEN OUTPUT "Pass" ENDIF → THEN is indented by only two spaces under IF, and the statement inside is indented by four
Nested statements keep indenting: an IF inside a loop is four spaces in, and its THEN part goes further in → WHILE N < 5 DO IF N = 3 THEN OUTPUT N ENDIF N ← N + 1 ENDWHILE
ELSE lines up with THEN at two spaces, and the statements under each are indented four spaces → IF Age >= 18 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
FOR Count ← 1 TO 3 OUTPUT Count NEXT Count → The loop body is not indented. OUTPUT Count should be moved in by four spaces.
IF Age >= 18 THEN OUTPUT "Adult" ENDIF → THEN is indented by four spaces. It should be indented by only two spaces.

Key Term

indentation
Statements inside a loop or IF are moved in by four spaces, but THEN and ELSE are moved in by only two. Nested statements keep indenting, which makes the structure easy to read.

Fill in the Blanks

1. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Hint: Type the loop counter variable that the indented loop body outputs.
2. ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword, indented by only two spaces, that introduces the alternative branch.
3. WHILE Total < 100 DO Total ← Total + 10 ENDWHILE
Hint: Type the keyword that closes the loop, lined up with the WHILE that opened it.
4. FOR Row ← 1 TO 3 FOR Col ← 1 TO 3 OUTPUT Row * Col
Hint: Type the keyword that starts the inner nested loop, indented four spaces inside the outer loop.
5. REPEAT INPUT Guess UNTIL Guess = 7
Hint: Type the command that reads a value from the user inside the indented loop body.

Spot the Error

Question 1
A FOR Count ← 1 TO 3
B OUTPUT Count * 2
C ENDWHILE
Line C — The closing keyword lines up with the FOR line at the left margin, and a FOR loop is closed with NEXT Count. ENDWHILE closes a WHILE loop. It should be 'NEXT Count'.
Question 2
A WHILE Score < 10
B Score ← Score + 1
C OUTPUT Score
D ENDWHILE
Line A — The WHILE header ends with DO, and the loop body is then indented by four spaces underneath it. The header should be 'WHILE Score < 10 DO'.
Question 3
A IF Age >= 18
B THEN
C THEN OUTPUT "Adult"
D ENDIF
Line C — THEN sits on its own line, indented by two spaces. The statement inside the IF goes on its own line, indented by four spaces. It should be ' OUTPUT "Adult"'.
Question 4
A IF Age >= 18 THEN
B THEN
C OUTPUT "Adult"
D ENDIF
Line A — THEN must not be written on the IF line. It goes on its own line, indented by two spaces. The first line should be 'IF Age >= 18'.
Question 5
A IF Score > 50
B ELSE
C OUTPUT "Pass"
D ENDIF
Line B — The line after the IF condition is THEN, indented by two spaces. ELSE only comes after the THEN statements. It should be ' THEN'.

Student with a class code? Join your class →