Skip to content
Menu

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.

Whiteboard video lesson: Nested loops and debugging

15-minute video lesson

Teaching, worked examples and 20 practice questions solved step by step.

Watch free for a month

What your child will learn

  • Explain nested loops
  • Calculate total repeats
  • Debug common loop errors
  • Use predict-run-fix

The method

  1. Predict.
  2. Run.
  3. Spot.
  4. 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?

  1. Step 1: Read the code
  2. Step 2: Inner loop: 5 times
  3. Step 3: Outer loop runs that 2 times: 2 × 5 = 10

Answer: 10 times

Question 2

How many times does it say Hi?

  1. Step 1: Read the code
  2. Step 2: Inner loop: 3 times
  3. Step 3: Outer loop runs that 4 times: 4 × 3 = 12

Answer: 12 times

Question 3

How many times does it play the drum?

  1. Step 1: Read the code
  2. Step 2: Inner loop: 5 times
  3. Step 3: Outer loop runs that 5 times: 5 × 5 = 25

Answer: 25 times