1
Algorithms, bugs and repeats
Computing 2: Units 1–4, pp. 8–65
GoalReview precise algorithms, programs, bugs and repeat blocks with new questions.
New words
algorithm · a precise set of steps in the right orderbug · a mistake in an algorithm or a programrepeat · to do something again
Explanation
An algorithm is a set of precise steps in the right order. A program is an algorithm that is changed into code, block by block. A bug is a mistake, and debugging means finding and fixing it. A repeat block runs the blocks inside it again and again. Blocks outside the repeat block run only once. Trace a program step by step to see what it does.
Worked examples
| Not precise | Precise |
|---|---|
| Water the plants | Fill the can with water |
| Pour some water on each plant |
| After | Across | Up | Hops |
|---|---|---|---|
| right 2 | 2 | 0 | 0 |
| round 1 | 2 | 1 | 1 |
| round 2 | 2 | 2 | 2 |
| Step | With a bug | Fixed |
|---|---|---|
| 1 | Zip the bag | Put in the books |
| 2 | Put in the books | Put in the lunchbox |
| 3 | Put in the lunchbox | Zip the bag |
Class activity
Partner programs: write a program for your partner on six paper cards: start, walk 2 steps, a repeat card with the number 3, clap, stop. Put the clap card inside the repeat card. Your partner follows the cards exactly. Then swap two cards by mistake so that the program has a bug. Can your partner find it and fix it? Finish by saying why a precise algorithm matters.
Practice
1
The algorithm says: start on tap, move up 4, hop 2, stop. Which block does not match?
The move up block. It says up 3, but it should say up 4.
2
Use a repeat block for right 3, right 3, right 3, right 3. How far does the character go?
Repeat 4 times: right 3. It goes 12 squares in all (4 × 3 = 12).
3
Which algorithm is more precise? A: Draw some flowers. B: Draw 3 red flowers.
B. It says how many flowers and which colour.
4
How many times does the say block run, and how many times does the hop block run?
The say block runs once. The hop block runs 4 times.