Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

A Bug in a Loop

There's a bone on every other tile of the path. The program is almost done, but the dog only picks up one bone and doesn't reach the goal. The program has two bugs. Run it and find them.

Two kinds of bugs are common in loops:

  • The wrong number of passes. The loop runs one pass more or fewer than it should. Count how many times the pattern should repeat.
  • A block in the wrong place. A block that should repeat is under the loop, so it's only carried out once. Or the other way around: a block that should be carried out once is inside the loop.

If you're not sure, watch the blocks light up: you'll see which blocks repeat and which are carried out just once. Fix the bugs one at a time: fix the first one, run the program again and see what changed. Not every bug is one of these two kinds, though: sometimes a block is simply missing.

Instructions

  1. 1

    Fix the program so that the dog picks up all the bones.

  2. 2

    And walks to the goal.

Back

9/11

  1. 1. Repeating Moves
  2. 2. Loops
  3. 3. Stairs
  4. 4. After the Loop
  5. 5. Quiz: Pass by Pass
  6. 6. A Bone on Every Tile
  7. 7. Around the Flower Bed
  8. 8. A Loop in a Loop
  9. 9. A Bug in a Loop
  10. 10. Quiz: A Bug in a Nested Loop
  11. 11. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.