3
From algorithm to program
Computing 2: Unit 1, pp. 8–23
GoalSay that a program is an algorithm changed into code that a computer can follow.
New words
program · a set of instructions that a computer understandscode · the instructions of a programScratchJr · a free app where you build programs with picture blocks
Explanation
People can follow an algorithm. A computer needs a program. To make a program, we change each step of the algorithm into a block of code. The computer then follows the blocks one by one. A computer cannot think on its own, so the blocks must be exact. Computer games are programs too.
Worked examples
Algorithm: 1 Start on the green flag. 2 Move right 6. 3 Stop. Each step becomes one block.
Algorithm: 1 Start on tap. 2 Hop 3. 3 Say “Yay!”. 4 Stop. Now there are four blocks.
A computer cannot think on its own. If the program says move right 6, the character moves right 6 squares. It cannot know that you wanted 7.
Class activity
Be the computer (two players): one player is the programmer and the other is the computer. The programmer lays out four paper cards in a row: start, forward 3 steps, clap 2 times, stop. The “computer” does exactly what the cards say and nothing more. Then the programmer changes one card, for example forward 5 steps, and the computer runs the program again. If you have a computer or tablet, an adult can open ScratchJr so you can build the same blocks.
Practice
1
Sami’s program says “move right 3”, but he wanted his car to move right 5. What will the car do?
It moves right 3. The computer does exactly what the code says, not what Sami wanted.
2
Write the algorithm for this program.
1 Start on the green flag. 2 Move right 4. 3 Hop 2. 4 Stop.
3
Which algorithm matches the blocks? A Start on tap, move up 3, stop. B Start on tap, move up 5, stop.
A. The number under the arrow is 3.
4
What do we call the instructions inside a program?
Code.