Use nested selection and iteration
Place one control structure inside another while keeping each condition and level readable.
Section 8 · Programming
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
What does indentation show in nested pseudocode?
What you will learn
- Trace nested IF statements
- Combine loops and selection
- Keep nesting within the syllabus limit of three levels
Nesting places a structure inside another
A nested IF runs only when control reaches the outer branch that contains it. Indentation should make the levels visible, and each structure needs its own closing keyword.
Nested iteration places one loop inside another. For each outer pass, the complete inner loop runs; this is useful for processing rows and columns in a two-dimensional structure.
Keep the logic no deeper than needed
Cambridge candidates are not required to write more than three levels of nested statements. Decompose complicated decisions into procedures or simpler stages where appropriate.
Trace the outer variable and inner variable separately. Reset an inner counter at the correct point if the algorithm needs it to start again for every outer pass.
Pause and explain
A body is inside a loop nested in another loop. How often does it run?
Worked example
A 2 by 3 grid is visited row by row. How many cells are processed?
Show the worked solution
- The outer loop runs for two rows.
- For each row, the inner loop runs for three columns.
- The nested body runs 2 × 3 = 6 times.
Answer Six cells are processed; the inner loop completes three times for each of two outer iterations.
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.
A loop visits 3 classrooms and checks 4 desks in each. How many desk checks occur?
Give me a hint
Multiply the inner loop count by the number of outer passes.
Compare my reasoning
- The classroom loop runs 3 times.
- The desk loop runs 4 times for each classroom.
- 3 × 4 = 12 checks.
12 desk checks.
Look for these in your work
- Outer count
- Inner count
- Total executions
Describe a nested IF for a member discount: only members receive a discount, and members aged under 18 receive 20%, while other members receive 10%.
Give me a hint
The age test belongs inside the member branch.
Compare my reasoning
- Test IsMember first.
- Inside the true branch, test Age < 18.
- Choose 20% or 10%; non-members receive no discount.
Use an outer member IF and a nested age IF in its true branch; handle non-members separately.
Look for these in your work
- Outer condition
- Nested condition
- All outcomes
A programmer nests four IF statements. What limit does the syllabus state, and give one way to simplify the design.
Give me a hint
The limit is about required nested statement depth.
Compare my reasoning
- Candidates are not required to write more than three levels.
- Identify a repeated or separable decision.
- Move a coherent task into a procedure or simplify conditions.
The syllabus limit is three nested levels; decompose part of the logic into a procedure or reduce redundant tests.
Look for these in your work
- Limit stated
- Practical simplification
Common mistakes
- Closing the wrong IF or loop
- Forgetting that the inner loop runs again for every outer pass
- Exceeding three levels when the logic can be simplified
What can you explain now?
If an outer loop runs 4 times and an inner loop runs 3 times per outer pass, how many times does the inner body run?
Compare with the explanation
12
Four groups of three give 12 executions.
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 does the inner loop do during each pass of an outer loop?
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.