Summary
In this lesson, you learned that:
- The
If …block carries out the blocks inside it only when its condition is true, and at most once. To decide on every tile, put it in a loop. If … elsechooses between two options: exactly one of its two parts is carried out, never both and never neither. In a loop, each pass carries out only one of them: a pass in which the dog turns doesn't move it.- The dog's senses are conditions:
bone here,path ahead,path to the leftandpath to the right. Left and right are from the dog's point of view. - An
Ifdoesn't have to be inside a loop. Where the dog decides just once, as in the Which Way at the Corner? exercise, theIfgoes between other blocks, and the program goes on under it. - An
Ifcan hold many blocks, such as a whole trip into a niche and back. At the end of the trip, check which way the dog faces. - An
Ifinside anotherIfis a nested condition. The inner decision is made only when the outer one came out "no", so it goes into the else part.
Practice: the corridor with niches is back, but this time, some niches are empty. A dog that tries to pick up a bone in an empty niche stops with an error: "There's no bone here." Build the whole program again, from the start.
In the next lesson, Not, you'll learn to turn a condition around, so that the dog can, for example, walk on until it finds a bone.
Instructions
- 1
Pick up all the bones on all the maps.
- 2
Walk to the goal.