Summary
In this lesson, you learned that:
- A function is a block of your own. You define it with
Define trick: you rename it and snap under it the blocks that the function carries out. Those blocks don't run by themselves. - Once a function is defined, the column of blocks offers a block with its name. Putting that block into the program calls the function: the dog carries out all the blocks of the function and then goes on under the call.
- A function pays off where the same blocks are needed in several places, especially where the places are irregular and no loop fits. The Define block and each call count as one block.
- A good name says what the function does:
goAround,fetch. A name is one word. - A call can go into a loop, and a loop can go into a function. A function with a loop and a condition in it, such as
fetch, searches: it does as much as each place needs. - A program can have several functions, and a function can call another one.
- A bug in a function shows up wherever the function is called, and one fix in the function repairs every call.
Time to practice. Bones mark the turns again, but this time, the dog turns left and right in turn: left at the first bone, right at the second, left at the third and right at the fourth. Each map has its own distances.
In the next lesson, Final Project: The Maze, the dog finds its way through hedge mazes, and you'll put together everything from this course.
Instructions
- 1
Pick up all the bones on all three maps. Define
fetchagain, and call it from a loop. - 2
Use at most 12 blocks.