← IGCSE Computer Science Paper 2

Indenting statements by four spaces

Indent every statement inside a FOR, WHILE or REPEAT loop by 4 spaces. Nested loops add 4 more; wrapped continuation lines use 2. An unindented loop body is a presentation error.

Understanding Indenting statements by four spaces in IGCSE Computer Science Paper 2

What it does: The statement between WHILE and ENDWHILE has 4 spaces of indentation, while WHILE and ENDWHILE are not indented. The loop body is indented by 4 spaces, and the wrapped continuation line is indented by 2 extra spaces to show it continues the OUTPUT. The closing keyword is not part of the body. It lines up with the keyword that opened the loop. An unindented loop body is a presentation error. The student loses marks for layout even if the logic is correct.

Common mistakes: This statement is inside the FOR loop, so it must be indented by four spaces, level with INPUT Num. It is also at the left margin and uses = instead of ←. It should be ' Total ← Total + Num'. Total ← 0 comes before the loop, so it is not inside it and must not be indented. The identifier should also be in Pascal case. It should be 'Total ← 0'.

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 136–145) and word search (Modules 123–145).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which FOR loop is laid out correctly in IGCSE pseudocode?
FOR Count ← 1 TO 5 OUTPUT Count NEXT CountFOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Matches
FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
↓
The loop body is not indented. OUTPUT Count should start with 4 spaces to show it belongs to the FOR loop. This is a presentation error.
Applying
Meanings
Term
4 spaces
Meaning
Indent every statement inside a FOR, WHILE or REPEAT loop by 4 spaces. Nested loops add 4 more; wrapped continuation lines use 2. An unindented loop body is a presentation error.
Practice
Total ← 0
Testing
Gaps
OUTPUT Count
Check Answer
Spots
3 INPUT Num
4Total = Total + Num

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

The 'Void Whale' badge — Definition Drifter, 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 FOR loop is laid out correctly in IGCSE pseudocode?
A. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
B. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count ✓
Statements inside a loop are indented by four spaces. Leaving the body unindented is a presentation error.
2. How far should a statement inside a WHILE loop be indented?
A. 4 spaces ✓
B. No indent, level with WHILE
The body of a WHILE loop is indented by four spaces. ENDWHILE goes back level with WHILE.
3. Which REPEAT loop is indented correctly?
A. REPEAT INPUT Guess UNTIL Guess = 7
B. REPEAT INPUT Guess UNTIL Guess = 7 ✓
The statements between REPEAT and UNTIL are indented by four spaces so they are clearly part of the loop.
4. A FOR loop sits inside another FOR loop. How is the inner loop's body indented?
A. 8 spaces: 4 for the outer loop plus 4 for the inner loop ✓
B. 4 spaces, the same as the outer loop's body
Each nested loop adds another four spaces. The inner body is two levels deep, so it is indented by 8 spaces.
5. Where should NEXT, ENDWHILE or UNTIL be placed?
A. Level with the FOR, WHILE or REPEAT that it closes ✓
B. Indented four spaces like the loop body
The closing keyword is not part of the body. It lines up with the keyword that opened the loop.

Match the Pairs

FOR Count ← 1 TO 5 OUTPUT Count NEXT Count → The OUTPUT line is indented by 4 spaces to show it is inside the FOR loop and repeats each time
FOR Row ← 1 TO 3 FOR Col ← 1 TO 3 OUTPUT Row * Col NEXT Col NEXT Row → Nested loops: the inner FOR is 4 spaces in and its body is 8 spaces in, because each nested loop adds 4 more spaces
The body of a WHILE loop is indented by 4 spaces, and ENDWHILE lines up with WHILE → WHILE Total < 100 DO Total ← Total + 10 ENDWHILE
Inside a loop, a statement that wraps onto a second line has its continuation line indented by 2 more spaces → REPEAT INPUT Score OUTPUT "Score is ", Score UNTIL Score > 50
FOR Count ← 1 TO 5 OUTPUT Count NEXT Count → The loop body is not indented. OUTPUT Count should start with 4 spaces to show it belongs to the FOR loop. This is a presentation error.
FOR Row ← 1 TO 3 FOR Col ← 1 TO 3 OUTPUT Row * Col NEXT Col NEXT Row → The body of the inner loop is only indented by 4 spaces, level with the inner FOR. It needs 8 spaces because each nested loop adds 4 more.

Key Term

4 spaces
Indent every statement inside a FOR, WHILE or REPEAT loop by 4 spaces. Nested loops add 4 more; wrapped continuation lines use 2. An unindented loop body is a presentation error.

Fill in the Blanks

1. FOR Count ← 1 TO 5 OUTPUT Count NEXT Count
Hint: Type the indentation that shows this statement belongs inside the FOR loop (use spaces).
2. WHILE Total < 100 DO Total ← Total + 5 ENDWHILE
Hint: Type the keyword that closes the loop. It sits at the same level as WHILE, not indented.
3. FOR Row ← 1 TO 3 FOR Col ← 1 TO 3 OUTPUT Row * Col
Hint: Type the indentation for a statement inside the inner loop. It is two loop levels deep, so add the indent once for each level.
4. OUTPUT "Your total score for the quiz is ", TotalScore, " points"
Hint: Type the indentation used for a wrapped continuation line. It is smaller than a loop indent.
5. REPEAT INPUT Guess UNTIL Guess = 7
Hint: Type the keyword that ends a REPEAT loop. It is written at the left margin, level with REPEAT.

Spot the Error

Question 1
A Total ← 0
B FOR Count ← 1 TO 5
C INPUT Num
D Total = Total + Num
E NEXT Count
Line D — This statement is inside the FOR loop, so it must be indented by four spaces, level with INPUT Num. It is also at the left margin and uses = instead of ←. It should be ' Total ← Total + Num'.
Question 2
A total ← 0
B FOR Count ← 1 TO 3
C Total ← Total + Count
D NEXT Count
E OUTPUT Total
Line A — Total ← 0 comes before the loop, so it is not inside it and must not be indented. The identifier should also be in Pascal case. It should be 'Total ← 0'.
Question 3
A while Lives > 0 DO
B INPUT Move
C Lives ← Lives - 1
D ENDWHILE
Line A — The WHILE line starts the loop and is not inside another loop, so it stays at the left margin. Only the statements between WHILE and ENDWHILE get four spaces. The keyword should also be in capitals: 'WHILE Lives > 0 DO'.
Question 4
A REPEAT
B INPUT Password
C Count ← Count + 1
D output "Try again"
E UNTIL Password = "abc"
Line D — Every statement between REPEAT and UNTIL is indented by four spaces, not two, and the keyword OUTPUT is written in capitals. It should be ' OUTPUT "Try again"'.
Question 5
A FOR Row ← 1 TO 3
B FOR Col = 1 TO 4
C OUTPUT Row * Col
D NEXT Col
E NEXT Row
Line B — The inner FOR loop is inside the outer loop, so it must be indented by four spaces. It also uses = instead of ← for the loop start. It should be ' FOR Col ← 1 TO 4'.

Student with a class code? Join your class →