3
Predict and debug
Computing 1: Topics 1.1–1.4, pp. 9–59
GoalPredict where a program ends, and find and fix a bug.
New words
predict · say what will happen before it happensdebug · find a bug and fix it
Explanation
To predict, trace the code first. Check the start square and the way the robot faces. A turn does not move the robot. Four quarter turns make a full turn. If the robot goes wrong, there is a bug. Find it, fix it, and test it again.
Worked examples
Predict: start at the bottom right of a 4 by 4 grid, facing up. Code: F F L F. It goes up two, turns left, forward one. It ends at C3.
Full turn: the robot faces up. R R R R makes four quarter turns. It faces up again. R R R is a bug if you wanted a full turn.
Bug fix: the robot should reach the star. Code: F F R F F. It goes the wrong way! The bug is the R. Fix: F F L F F.
Class activity
Term 1 challenge: use cards and a floor grid. Make a route of five cards. Predict the end square. Walk it. Then change one card to add a bug on purpose. Swap with a partner. They find the bug, fix it and test.
Practice
1
The robot starts facing up. The code is R R. Which way does it face?
Down.
2
The robot should face the opposite way. The code is R. Fix it.
Add one more R: R R. Two quarter turns make a half turn.
3
The robot should reach the flower. Code: F F L F F. It ends one square past the flower. What is the bug?
One F too many at the end. The fix is F F L F.
4
After you fix a bug, what do you do?
Test the program again.