Programming for Children
Primary 6 · Science and Elementary Technology
Programming for Children
Lesson 1 of 6
30 min
Let's begin
At break time Byiringiro draws a grid of squares on the ground with chalk. His friend Mutesi stands on one square and pretends to be a robot. She may only obey three commands: FORWARD (one square), LEFT and RIGHT (turn on the spot). Byiringiro wants her to reach the football, so he calls out: "Forward, forward, left, forward." Mutesi ends up one square away from the ball!
Byiringiro looks at his instructions again and finds his mistake: he should have said right, not left. He has just done what every programmer does: he wrote a program, tested it, found a bug and fixed it.
A program is a list of instructions that a computer follows, one after another. The person who writes it is a programmer. A computer does exactly what the program says; it cannot guess what you meant. So instructions must be exact and in the right order.
Programs are written to solve problems for people: working out bills, drawing pictures, running games, or guiding a Zipline drone to the right health centre.
| Idea | Meaning | Robot game example |
|---|---|---|
| Sequence | Instructions run in order, from the first to the last. | Changing the order changes where Mutesi ends up. |
| Loop | Repeat some instructions many times. | "Repeat 3 times: forward" instead of saying forward three times. |
| Condition | Do something only IF something is true. | "If you are in front of the ball, stop." |
Turtle Blocks (called Turtle Art on some XO laptops) is a free programming tool. You can use it as an activity on XO laptops or online at turtle.sugarlabs.org. On the screen there is a turtle holding a pen. As the turtle moves, it draws a line. You program it by snapping blocks together:
The turtle starts in the middle of the screen, facing up.
A square has 4 equal sides and 4 right angles. The turtle draws it like this:
forward 100, right 90
forward 100, right 90
forward 100, right 90
forward 100, right 90
The same two blocks happen four times, so we can use a loop:
repeat 4
forward 100
right 90
A regular polygon has all sides equal and all angles equal. To get back to where it started, the turtle turns a full circle, 360°, shared equally between the corners:
turn at each corner = 360 ÷ number of sides
| Shape | Sides | Turn | Program |
|---|---|---|---|
| Equilateral triangle | 3 | 360 ÷ 3 = 120 | repeat 3 [forward 100, right 120] |
| Square | 4 | 360 ÷ 4 = 90 | repeat 4 [forward 100, right 90] |
| Pentagon | 5 | 360 ÷ 5 = 72 | repeat 5 [forward 100, right 72] |
| Hexagon | 6 | 360 ÷ 6 = 60 | repeat 6 [forward 100, right 60] |
| Octagon | 8 | 360 ÷ 8 = 45 | repeat 8 [forward 100, right 45] |
Notice: the number in repeat is always the number of sides.
Tip
The turtle always goes all the way round (360°) to get home. Share 360 between the corners: 360 ÷ number of sides gives the turn. And repeat as many times as there are sides.
Answers
What you learned today
Sources and credits
The exercises (Try it yourself and the practice questions) are written by Ganzaa. The Turtle Blocks part of this lesson is written by Ganzaa; Turtle Blocks is free software from Sugar Labs.
This lesson adapts CC BY-SA material and is shared under CC BY-SA 4.0.
Quick check
Match each word to its meaning.
Tap one on the left, then its partner on the right.