Year 4 (ages 8–9, Grade 3 in the US) · Computing · Loops in Scratch · Lesson 4
Nested loops and debugging
Nested loops (a loop inside a loop) for patterns and counting repeats, plus a step-by-step method for debugging loop programs.
Exam boards: this lesson matches the AQA and Pearson Edexcel GCSE computing courses. Check which course your school follows.

15-minute video lesson
Teaching, worked examples and 20 practice questions solved step by step.
Watch free for a monthWhat your child will learn
- Explain nested loops
- Calculate total repeats
- Debug common loop errors
- Use predict-run-fix
The method
- Predict.
- Run.
- Spot.
- Fix + test.
Key words: nested loop, debug, bug, repeat, predict, test.
Worked examples
Worked examples from the lesson, with every step.
Question 1
How many times does it clap?
- Step 1: Read the code
- Step 2: Inner loop: 5 times
- Step 3: Outer loop runs that 2 times: 2 × 5 = 10
Answer: 10 times
Question 2
How many times does it say Hi?
- Step 1: Read the code
- Step 2: Inner loop: 3 times
- Step 3: Outer loop runs that 4 times: 4 × 3 = 12
Answer: 12 times
Question 3
How many times does it play the drum?
- Step 1: Read the code
- Step 2: Inner loop: 5 times
- Step 3: Outer loop runs that 5 times: 5 × 5 = 25
Answer: 25 times