2
Trace a longer program
Computing 2: Unit 1, pp. 8–23
GoalTrace a longer program block by block and say what the character does.
New words
trace · to follow a program step by step to see what it doeshop · to jump up and downsequence · blocks that run one after the other
Explanation
A longer program is still steps in order. Read it from left to right. Do one block at a time. This is called tracing. Write down what happens after each block. After the last block you know the result. Tracing helps you find mistakes before you run the program.
Worked examples
| After block | Across | Up |
|---|---|---|
| start | 0 | 0 |
| up 2 | 0 | 2 |
| right 3 | 3 | 2 |
| up 1 | 3 | 3 |
This program moves, says “Hi!” and then makes a half turn. The character does the things in that order.
The order matters. Hop and then say is not the same as say and then hop. The character does the first block first.
Class activity
Act out a trace (two or three players): write five cards: take 3 steps forward, hop 2 times, spin right 12 (turn around once), clap 2 times, say “Yes!”. One player turns over one card at a time and does it. Another player draws a tick for each card on a list. Then shuffle the cards and trace the new order. How is the result different?
Practice
1
The character starts at 0 across and 0 up. It runs: right 2, up 3, right 1. Where does it finish?
3 across and 3 up.
2
The character should make a quarter turn to the right after it moves right. Which block is missing?
A turn right block with 3 under it (3 is a quarter turn).
3
The algorithm says: say Hello, then move right 5. Which two blocks should swap places?
The move right 5 block and the say block.
4
How many blocks does this program have: start on tap, hop 2, spin right 6, say “Hi!”, stop?
Five blocks.