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
Fix the program so that the dog picks up all the bones.
- 2
And walks to the goal.