What is an executor?
An executor is anything that carries out commands: a robot, a drawing turtle, a calculator, or a computer. It has a fixed list of commands it understands, called its command set. It does exactly what is written. It never guesses what you meant.
Our robot lives on a grid. Its command set is: F (go forward one square), L (turn left on the spot), R (turn right on the spot). An algorithm is a list of these commands. The aim is to reach the star.
Tracing an algorithm
To analyse an algorithm means to find out what it really does. The best tool is tracing: play the executor yourself, one command at a time, and write down the state after each command (position and the way it faces).
| Command | Position | Faces |
|---|---|---|
| start | (1, 6) | up |
| F | (1, 5) | up |
| F | (1, 4) | up |
| F | (1, 3) | up |
| R | (1, 3) | right |
A turn changes only the direction. A forward step changes only the position. Trace tables like this are used by programmers every day.
Syntax errors
Syntax means the spelling and grammar rules of a language. A syntax error is a place where the program breaks those rules. Examples: a command with a wrong spelling (FORWAD), a missing bracket, a command the executor does not have.
- The executor cannot carry out that line, so it stops or refuses to start.
- It usually tells you the line number. So syntax errors are the easy ones to find and fix.
Logic errors
A logic error (also called a bug in the thinking) means the program is written correctly, runs without any message, but does not do what you wanted. The robot turned after 2 steps instead of 3, so it stopped one square short.
- The computer cannot see this, because it does not know your goal.
- You find it by tracing and by comparing the result with what you expected.
How to debug: (1) run it, (2) compare the result with the goal, (3) trace to find the first wrong line, (4) fix only that line, (5) run again.
Coordinates in computer graphics
To tell a computer where a dot is, we use two numbers: (x, y). On a screen, the origin (0, 0) is the top-left corner.
- x grows to the right.
- y grows downwards. This is the opposite of a maths graph, where y goes up.
The point (5, 2) is 5 across and 2 down. Our robot grid follows the same rule, so the squares in each row below the top have bigger y. When a drawing executor moves "up", its y gets smaller.
To change a screen y into a maths y on a screen with H rows (0 to H − 1): maths y = (H − 1) − screen y.
Try it yourself
In the 3D: in the last step, reach the star with exactly 7 commands. Then make a logic error on purpose, and then explain to a friend how you would find it.
At home: draw an 8 × 8 grid on paper. Write a program for a friend (F, L, R only) to walk from one square to another. Let the friend act as the robot with a pencil. Where it goes wrong, you have found a bug.
Key formulas and definitions
- Forward: the square next to you in the facing direction
- L: direction turns 90° left; R: 90° right
- Screen coordinates: origin (0, 0) at top-left, x → right, y ↓ down
- Maths y = (H − 1) − screen y (H rows, numbered from 0)
Worked examples
1. Trace: robot at (2, 5) facing up. Program: F F R F. Where does it end?
F: (2, 4). F: (2, 3). R: now faces right. F: (3, 3). It ends at (3, 3) facing right.
2. A program has the line "FORWRD". What kind of error is it and what happens?
A syntax error. FORWRD is not a command, so the executor stops at that line and reports it.
3. The robot should walk 4 squares up from (1, 6) but the program is F F F. What kind of error is it? How to fix it?
A logic error. The program runs but ends at (1, 3) instead of (1, 2). Fix: add one more F.
4. A dot is at x = 4, y = 3 on the screen. Describe where it is.
4 squares to the right of the left edge, and 3 squares down from the top edge.
5. A turtle at (3, 3) facing up moves F F. What is its new y?
Up on the screen means y gets smaller. 3 − 2 = 1. New position (3, 1).
6. The robot at (1, 6) facing up must reach (4, 3). Give the shortest program.
Three squares up and three squares right: F F F R F F F. That is 7 commands.
Common mistakes
- Thinking the computer will guess what you meant. An executor does exactly what the commands say.
- Not tracing: running the program once, seeing it "nearly works" and guessing the fix.
- Mixing up the two errors: a wrong spelling is syntax; a wrong count or order is logic.
- Using maths-graph habits on a screen: y does NOT go up. On a screen, going up makes y smaller.