3
Fix it and run again
Computing 1: Topic 1.4, pp. 49–59
GoalFix a bug in code and run the program again to check it.
New words
fix · change the code so that it is righttest · run the code to see if it works
Explanation
First find the bug. Then change the card. Then run the code again. This is called testing. If the robot reaches the goal, the bug is fixed. If not, there may be another bug. Look again. Be patient!
Worked examples
Code: F F R F F F ends one square below the star. The robot should go up three first. Fix: add an F at the start. New code: F F F R F F F.
Some programs have two bugs. Code: F L F F F. The robot should reach the tree. Fix: F F L F F. It needs two squares up and then two squares left, not one up and three left.
After a fix, always test. If the robot is still wrong, look for another bug. Keep trying until it works.
Class activity
Fix and test: use the code from the bug detective game. Fix your friend’s bug. Walk it on the floor grid. Did the toy reach the goal? If not, look for a second bug. Say what you changed.
Practice
1
The robot starts at the bottom left facing up. The flower is two squares up and two squares right. The code F F R F stops short. Fix it.
It needs one more F at the end: F F R F F.
2
After you fix a bug, why do you run the code again?
To check that the bug is really fixed.
3
You tested the fix and the robot is still wrong. What do you do?
Look for another bug.
4
Which button must be pressed to run the program?
GO.