← IGCSE Computer Science Paper 2

Indenting THEN and ELSE by two spaces

THEN and ELSE sit two spaces in from IF, on their own lines. The statements inside each go further in, and ENDIF lines up with IF. Nested IFs keep the same two-space step.

Understanding Indenting THEN and ELSE by two spaces in IGCSE Computer Science Paper 2

What it does: THEN and ELSE have two spaces, the OUTPUT statements have four, and ENDIF starts in the same column as IF. THEN goes on its own line, indented two spaces in from IF, because it continues the IF statement.

Common mistakes: THEN is already on line 2, on its own line two spaces in. The statement inside it must go on its own line, indented further to four spaces: ' OUTPUT "Adult"'. THEN must not be written on the IF line. It goes on its own line, indented two spaces in from IF. Line 1 should be just 'IF Score >= 50'.

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 156–165) and word search (Modules 146–165).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which layout puts THEN in the correct place?
IF Mark >= 50 THEN OUTPUT "Pass" ENDIFIF Mark >= 50 THEN OUTPUT "Pass" ENDIF
Matches
IF Score >= 50 THEN OUTPUT "Pass" ENDIF
↓
THEN is not indented. It must be two spaces in from IF, with the OUTPUT statement indented further.
Applying
Meanings
Term
THEN
Meaning
THEN and ELSE sit two spaces in from IF, on their own lines. The statements inside each go further in, and ENDIF lines up with IF. Nested IFs keep the same two-space step.
Practice
IF Score >= 50
Testing
Gaps
Check Answer
Spots
2 THEN
3 THEN OUTPUT "Adult"

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

The 'Lion' badge — Inheritance King, 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 layout puts THEN in the correct place?
A. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF ✓
B. IF Mark >= 50 THEN OUTPUT "Pass" ENDIF
THEN goes on its own line, indented two spaces in from IF, because it continues the IF statement.
2. How far is THEN indented from the IF line?
A. Two spaces ✓
B. Four spaces
THEN and ELSE move in by only two spaces. The statements inside them move in further, so they are not at the same level.
3. Where should ENDIF be written?
A. Lined up with THEN and ELSE
B. Lined up with the IF it closes ✓
ENDIF closes the whole IF statement, so it starts in the same column as IF.
4. Which layout positions ELSE correctly?
A. IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF ✓
B. IF Age >= 16 THEN OUTPUT "Adult" ELSE OUTPUT "Child" ENDIF
ELSE lines up with THEN, two spaces in from IF. If it is written at the IF level, it looks like a new statement.
5. Where do the statements inside THEN go?
A. In line with THEN
B. Further in than THEN ✓
The statements inside THEN and ELSE are indented further than the THEN or ELSE keyword, which shows they belong to that branch.

Match the Pairs

IF Age >= 16 THEN OUTPUT "Adult" → THEN is on its own line, two spaces in from IF. The statement inside THEN is indented further.
ELSE OUTPUT "Child" → ELSE is on its own line, two spaces in from IF. The statement inside ELSE is indented further.
THEN and ELSE are two spaces in from IF, the statements inside are indented further, and ENDIF lines up with IF. → IF Score >= 50 THEN OUTPUT "Pass" ELSE OUTPUT "Fail" ENDIF
A nested IF keeps the same two-space step. The inner IF sits inside THEN and its own ENDIF lines up with the inner IF. → IF Age >= 16 THEN IF Age >= 65 THEN OUTPUT "Senior" ENDIF ENDIF
IF Score >= 50 THEN OUTPUT "Pass" ENDIF → THEN is not indented. It must be two spaces in from IF, with the OUTPUT statement indented further.
IF Score >= 50 THEN OUTPUT "Pass" ENDIF → ENDIF is indented two spaces. It must line up with IF, in the same column.

Key Term

THEN
THEN and ELSE sit two spaces in from IF, on their own lines. The statements inside each go further in, and ENDIF lines up with IF. Nested IFs keep the same two-space step.

Fill in the Blanks

1. IF Score >= 50 THEN OUTPUT "Pass"
Hint: Type the keyword that continues the IF on its own line, indented two spaces, before the statements to run when the condition is true.
2. THEN OUTPUT "Pass" ELSE
Hint: Type the keyword for the alternative branch. It sits two spaces in, level with THEN.
3. ELSE OUTPUT "Fail" ENDIF
Hint: Type the keyword that closes the selection. It lines up with the IF, with no indent.
4. IF Mark >= 50 THEN OUTPUT "Pass"
Hint: Type the keyword that starts the selection. THEN is indented two spaces beneath it.
5. OUTPUT "Merit" ELSE OUTPUT "Pass"
Hint: This is a nested IF, so its alternative keyword is two spaces in from the inner IF. Type that keyword.

Spot the Error

Question 1
A IF Age >= 18
B THEN
C THEN OUTPUT "Adult"
D ELSE
E OUTPUT "Child"
F ENDIF
Line C — THEN is already on line 2, on its own line two spaces in. The statement inside it must go on its own line, indented further to four spaces: ' OUTPUT "Adult"'.
Question 2
A IF Score >= 50 THEN
B THEN
C OUTPUT "Pass"
D ELSE
E OUTPUT "Fail"
F ENDIF
Line A — THEN must not be written on the IF line. It goes on its own line, indented two spaces in from IF. Line 1 should be just 'IF Score >= 50'.
Question 3
A INPUT Temp
B IF Temp > 30
C THEN OUTPUT "Hot"
D OUTPUT "Hot"
E ENDIF
Line C — THEN sits on its own line, two spaces in from IF. The statement inside THEN belongs on the next line, indented four spaces: ' OUTPUT "Hot"'. The line should be just ' THEN'.
Question 4
A IF Passed = TRUE
B THEN
C OUTPUT "Well done" ENDIF
D ENDIF
Line C — ENDIF must be on its own line, lined up with IF at the left margin. It must not be added to the end of the statement line. The line should be ' OUTPUT "Well done"'.
Question 5
A IF Coins >= 10
B THEN OUTPUT "Buy"
C OUTPUT "Buy"
D ENDIF
Line B — THEN stays on its own line, two spaces in from IF. The statement inside it goes on the next line, indented further. Line 2 should be just ' THEN'.

Student with a class code? Join your class →