← IGCSE Computer Science Paper 2

Flowchart for a WHILE loop

In a flowchart the decision comes first. Yes runs the body and an arrow returns to the decision. No leaves the loop to the next step. The body may run zero times.

Understanding Flowchart for a WHILE loop in IGCSE Computer Science Paper 2

What it does: In a WHILE flowchart the Yes exit leads into the body. The last step of the body has an arrow back to the decision. The condition is checked before the body. If it is false at the start, the flowchart takes the No path and skips the body. No means the condition is false. The flow leaves the loop and carries on with the next step in the algorithm. Putting the body first and the test after it is the shape of a REPEAT ... UNTIL loop, not a WHILE loop.

Common mistakes: In a WHILE loop the Yes path runs the body and then an arrow goes back to the decision. It must not leave the loop. The line should be 'Yes: body, arrow to decision'. A WHILE loop is drawn with the decision before the body. The body-first version is a REPEAT loop. It should be 'Decision: Num > 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 188–213) and word search (Modules 188–231).

Take this worksheet further — free with Cloodit

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

Learning
Duo
In a flowchart for a WHILE loop, where is the decision diamond drawn?
After the loop bodyBefore the loop body
Matches
Start --> Count <- 1 --> OUTPUT Count --> Count <- Count + 1 --> Count <= 5 ? --Yes--> back to OUTPUT Count
↓
The body is placed before the decision, which draws a REPEAT ... UNTIL style loop. The body must run at least once, but a WHILE body may run zero times.
Applying
Meanings
Term
WHILE condition DO
Meaning
In a flowchart the decision comes first. Yes runs the body and an arrow returns to the decision. No leaves the loop to the next step. The body may run zero times.
Practice
Count ← 1
Testing
Gaps
Count <= 5 DO
Check Answer
Spots
3Decision: Count <= 3?
4Yes: body, arrow to STOP

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

The 'Barreleye Fish' badge — Clear Vision, 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. In a flowchart for a WHILE loop, where is the decision diamond drawn?
A. Before the loop body ✓
B. After the loop body
A WHILE loop tests the condition first. The decision comes before the body, so the body only runs if the condition is true.
2. A WHILE loop starts and its condition is false straight away. How many times does the body run?
A. At least once
B. Zero times ✓
The condition is checked before the body. If it is false at the start, the flowchart takes the No path and skips the body.
3. Which path from the decision runs the loop body in a WHILE flowchart?
A. The Yes path ✓
B. The No path
Yes means the condition is true, so the body runs. No means the condition is false, so the loop is left.
4. After the last statement in the loop body, where does the flow line go?
A. Straight on to the next step after the loop
B. Back up to the decision ✓
The arrow returns to the decision so the condition is tested again before the body can run another time.
5. What happens on the No path from the decision in a WHILE flowchart?
A. The loop ends and the flow moves to the next step ✓
B. The body runs one more time and then stops
No means the condition is false. The flow leaves the loop and carries on with the next step in the algorithm.

Match the Pairs

Decision diamond: Count <= 5 ? placed before the loop body → This is the test of a WHILE loop. It is checked first, so the body may run zero times if the condition is false at the start.
Arrow from the end of the loop body back up to the decision diamond → After the body runs, the flow returns to the condition so it can be tested again.
The Yes path from the decision runs the loop body, then returns to the decision → Count <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> back to Count <= 5 ?
The No path leaves the loop and continues to the next step of the algorithm → Count <= 5 ? --No--> OUTPUT "Finished"
Start --> Count <- 1 --> OUTPUT Count --> Count <- Count + 1 --> Count <= 5 ? --Yes--> back to OUTPUT Count → The body is placed before the decision, which draws a REPEAT ... UNTIL style loop. The body must run at least once, but a WHILE body may run zero times.
Count <= 5 ? --Yes--> OUTPUT Count --> Count <- Count + 1 --> OUTPUT "Done" → There is no arrow from the end of the body back to the decision, so the loop cannot repeat and the body only ever runs once.

Key Term

WHILE condition DO
In a flowchart the decision comes first. Yes runs the body and an arrow returns to the decision. No leaves the loop to the next step. The body may run zero times.

Fill in the Blanks

1. WHILE Count <= 5 DO OUTPUT Count ENDWHILE
Hint: Type the keyword that starts a loop whose condition is tested before the body runs.
2. WHILE Count <= 5 DO Count ← Count + 1 ENDWHILE
Hint: Type the relational operator meaning 'less than or equal to' so the loop keeps going while Count is at most 5.
3. Decision: Count <= 5? Yes: body, then arrow back to the decision No: go to next step
Hint: Type the flowchart shape that the return arrow from the loop body points back to.
4. Decision: Total < 20? No: leave the loop Yes: run the body
Hint: Type the label on the flow line that exits the loop when the condition is false.
5. Count ← 6 WHILE Count <= 5 DO // body runs 0 times
Hint: Type how many times the body runs when the condition is false the first time it is tested.

Spot the Error

Question 1
A START
B Count ← 1
C Decision: Count <= 3?
D Yes: body, arrow to STOP
E No: go to next step
Line D — In a WHILE loop the Yes path runs the body and then an arrow goes back to the decision. It must not leave the loop. The line should be 'Yes: body, arrow to decision'.
Question 2
A Body first, then Num > 0?
B Yes: Total ← Total + Num
C Yes: arrow back to decision
D No: exit to OUTPUT Total
Line A — A WHILE loop is drawn with the decision before the body. The body-first version is a REPEAT loop. It should be 'Decision: Num > 0?'.
Question 3
A Lives ← 3
B Process: Lives > 0?
C Yes: Lives ← Lives - 1, back
D No: next step
Line B — A condition with Yes and No paths is a decision, drawn as a diamond. It is not a process rectangle. It should be 'Decision: Lives > 0?'.
Question 4
A START
B OUTPUT Num
C Decision: Num < 10?
D Yes: INPUT Num, arrow back
E No: OUTPUT Num
Line B — The first value must be read in before the decision is tested, so the loop has a value to check. Outputting Num here uses it before it has a value. It should be 'INPUT Num'.
Question 5
A START
B Total ← 0
C Decision: Total > 50?
D Yes: add Mark, arrow back
E No: OUTPUT Total
Line C — Total starts at 0, so Total > 50 is false straight away. The body would be skipped and the loop would never total anything. The condition should be Total < 50.

Student with a class code? Join your class →