Finding Bugs
Even experienced programmers write programs that don't do what they should. A mistake in a program is called a bug, and finding and fixing it is called debugging. The name supposedly comes from a real moth that was found in 1947 inside one of the first computers, where it was causing a fault.
The best way to find a bug is to run the program and watch closely what happens:
- Watch the dog and the editor at the same time. The block the dog is carrying out lights up.
- Find the first place where the dog does something other than it should. When it bumps into a hedge or steps off the path, the program stops, and the block where that happened stays lit.
- The bug is usually in that block or a little before it. Think about what should have been there.
How to fix the program:
- Delete one block: click it and press the Delete key (or right-click it and choose to delete it). The blocks below it move up.
- Put a block in the middle of the program: drag it between two blocks. The other blocks make room for it.
- Careful when dragging: when you drag a block in the middle of a program, all the blocks below it come along. To pull out just that one block, hold Ctrl (Cmd on a Mac) while dragging.
Instructions
The program is already written, but it has a bug. Run it, find the wrong block and fix it so that the dog gets to the goal. Replacing a single block is enough.
Start programming for free
5/7