Learn in your language
Skip to content
IGCSE · Cambridge (CIE) · 0478

Repeat while a condition is true

Use a pre-condition loop when the body should run only while a condition holds.

Cambridge IGCSE Computer Science 0478 · Programming · 2026–2028 Version 6 · 8.1
Exam scope and assessment notes

This sequence follows Cambridge IGCSE Computer Science 0478, 2026–2028 syllabus Version 6. It covers section 8.1 (Programming concepts) only. Pseudocode examples use the published Cambridge format; the separate 2029–2031 syllabus is not mapped here. Practice is original, self-checked and does not award an official Cambridge grade. Full timed papers, a browser-based programming workspace and human subject-teacher review remain outstanding.

Before you begin

  • Be comfortable following an ordered algorithm and tracing variable values. Each lesson introduces the Cambridge pseudocode form it uses.

Work on paper. Try each question before revealing help, and explain why your method works.

Quick readiness check

When is the condition of a WHILE loop checked?

What you will learn

  • Trace a WHILE loop condition
  • Update values so the loop can end
  • Handle a condition that is false at the start

WHILE checks before each iteration

A pre-condition loop tests its condition before entering the body. If the condition is initially FALSE, the body runs zero times.

Change a value in the body so that a valid loop can eventually stop. Otherwise the condition may remain TRUE forever.

Choose a condition that matches the stop rule

WHILE attempts < 3 repeats as long as fewer than three attempts have been made. The final iteration should update Attempts so the next condition check can fail.

Use a pre-condition loop when zero repetitions is valid, such as reading while more data remains.

Pause and explain

What should a WHILE body usually do to a loop-control value?

Put the idea to work

Worked example

Start Count at 1 and output it while it is less than 4.

Show the worked solution
  1. Set Count ← 1.
  2. Check Count < 4 before each pass.
  3. Output Count and increment it, so the values are 1, 2 and 3.

Answer Count ← 1 WHILE Count < 4 DO OUTPUT Count Count ← Count + 1 ENDWHILE

Try a topic test

Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.

Test this topic →

From guided practice to a new situation

Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.

1 · Guided

Trace Count ← 2; WHILE Count <= 4: OUTPUT Count; Count ← Count + 1. Give the output sequence.

Give me a hint

Check the condition before each pass and update the count.

Compare my reasoning
  1. Count 2 passes and becomes 3.
  2. Count 3 passes and becomes 4.
  3. Count 4 passes and becomes 5; 5 <= 4 is false.

The output is 2, 3, 4.

Look for these in your work

  • Condition traced
  • Update traced
  • Output sequence
2 · Independent

Write a loop that processes scores while Count is less than 5, incrementing Count after each score.

Give me a hint

Place the increment inside the repeated body.

Compare my reasoning
  1. Test Count < 5 before processing.
  2. Process one score.
  3. Increment Count before the next condition check.

WHILE Count < 5 DO ProcessScore Count ← Count + 1 ENDWHILE

Look for these in your work

  • Pre-condition
  • Progress update
3 · Transfer

A WHILE loop reads another command while Command = "Y". Explain how to avoid repeating the same command forever.

Give me a hint

The loop body must obtain the next command.

Compare my reasoning
  1. Process the current command.
  2. Prompt and read a new Command inside the loop.
  3. The next condition check uses that new input.

Read a new Command in each iteration; stop when it is no longer Y.

Look for these in your work

  • New input inside loop
  • Stopping condition explained

Common mistakes

  • Forgetting the update and creating an infinite loop
  • Using a post-condition loop when zero runs are required
  • Changing the condition so it can never become false
Recall without your notes

What can you explain now?

Can a WHILE body run zero times?

Compare with the explanation

Yes, if its initial condition is false

The condition is tested before the first iteration.

After trying it yourself, choose your next review. This is your self-assessment.

Your review choice appears on Today. Sign in to sync it across devices.

Make it stick

What must happen inside a WHILE loop for it to make progress?

If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.

Keep learning Computer Science

Course scope and assessment

165 original lessons map the listed objectives across all 10 main topics in the 2026–2028 Version 6 syllabus, with worked explanations and guided, independent and transfer practice. This is mapped teaching coverage, not proof of full exam readiness. Three earlier starter lessons remain available but are not counted as syllabus-mapped teaching. Practical programming experience in an executable browser workspace, full timed-paper practice, human subject-teacher review and the separate 2029–2031 syllabus remain outstanding. Practice is self-checked and does not award an official Cambridge grade.

StudyForA · Learn with understanding

Original teaching content and links to official sources. Check your exam year and qualification before using a resource.