Summary
In this lesson, you learned that:
- A program has to work for data you don't know in advance. That's why exercises have several maps, and the program must work on all of them.
Repeat until at the goalrepeats its blocks until the dog is at the goal, however long the path is. It checks only before each pass, not between the blocks inside.- A condition, such as
path ahead, is a question whose answer is true or false. It goes into the hexagonal slot of another block, and it counts as a block too. Repeat whilerepeats its blocks as long as its condition is true. Withpath ahead, the dog walks to the end of a straight part, wherever that is.- Loops with conditions can be nested: the inner loop takes the dog to a corner, and the outer one repeats that until the goal.
- Bugs like to hide in the first and the last pass of a loop. Sometimes a block has to go before the loop so that every pass works.
- An endless loop never ends, because its passes don't bring it closer to the end. Every pass has to get the dog closer to the goal.
Time to practice. The path turns right at every corner, as in Corner After Corner, and this time, there's a bone in every corner.
In the next lesson, Conditions, the dog learns to make decisions, for example to pick up a bone only where there is one.
Instructions
- 1
Pick up all the bones on all three maps. Each pass can start by picking up the bone in a corner, as in Bones All the Way. What does the dog have to do before the loop then?
- 2
Walk to the goal.