← Back to course
Code Crew G3 / Week 06 / Wednesday
3/6
Week 06 Β· Debugging

Wednesday

// Finding the broken step

Wednesday: Loop Bugs

Rocket wants to clap five times. He writes a loop and runs it. He claps and claps and claps! "Why won't I stop?" he says with a grin.

Raven reads the code. "What do you notice? There are two REPEAT lines."

Nova says, "Loops and boxes can both have bugs. Check every number carefully." Let's help them fix the loop bugs and the box bugs.

These loops have bugs. Read carefully and fix each one.

(A) Goal: clap 5 times
    REPEAT 5 TIMES:
        REPEAT 5 TIMES:
            clap
What's the bug?
Fix:
(B) Goal: stop when bowl is empty
    REPEAT UNTIL the bowl is full:
        eat one bite
What's the bug?
Fix:

Variable Bugs

What's wrong with this score keeper?

score = 0
(after 3 goals)
score = 1
score = 1
score = 1
What's the bug?
Fix:

And this? Should be a count of jumps.

jumps = 0
(every jump)
jumps = jumps - 1
What's the bug?
Fix:
LOOP AND BOX BUGS
  • Read the question.
  • Tap your answer.
Goal: clap 4 times. Code: REPEAT 4 TIMES: (REPEAT 4 TIMES: clap). How many claps?
How do you fix that code?
Goal: count jumps. Code: jumps = jumps - 1. What should the minus sign be?
Goal: stop when the bowl is empty. Code says UNTIL the bowl is full. Which word is the bug?

Quick Check

Goal: clap 5 times. The buggy code puts REPEAT 5 TIMES inside another REPEAT 5 TIMES. How many claps happen? ____
WHY THIS EXERCISEAn extra loop multiplies the work. Counting the result helps you spot a loop bug.
← Tuesday