The idea
Suppose you want the cat to move ten times. You could drag ten move blocks. It would work.
It would also be slow to build, impossible to read, and a nightmare to change.
Instead you say it once and wrap it in a loop.
The long way — works, but do not
move 50 steps
move 50 steps
move 50 steps
move 50 steps
The same thing, said once
repeat 4
move 50 steps
Both do exactly the same. The second one is easier to read, faster to build, and if you want
forty instead of four you change one number.
New words
LoopA block that repeats what is inside it.
RepeatLoops a set number of times, then moves on.
ForeverLoops until you press stop. Never moves on.
Inside the loopThe blocks held by the C-shape. Those are the ones that repeat.
Do it — draw a square
This is the classic, and it is worth doing properly because it shows loops doing real work.
A square, in seven blocks
when green flag clicked
go to x: 0 y: 0
pen down
repeat 4
move 100 steps
turn 90 degrees
pen up
📷
images/l1-s7-script-square.png
Screenshot: the square script, with the two blocks clearly INSIDE the repeat C-shape
- Build it. The two blocks after repeat 4 must be inside the C-shape, not under it.
- Run it. You should get a square.
- Change repeat 4 to repeat 3 and turn 90 to turn 120. Run it. A triangle.
- Try repeat 5 with turn 72. Then repeat 6 with turn 60.
- Look at the pattern. What do the two numbers always multiply to?
💡 Tip
The two numbers always multiply to 360. That is the whole of turtle geometry in one sentence, and you just worked it out yourself rather than being told.
📷
images/l1-s7-stage-shapes.png
Screenshot: the stage showing a drawn square, and beside it a triangle and a pentagon
⚠ Careful
If the blocks are under the loop rather than inside it, the shape will not draw. Look carefully at where the C-shape wraps around them.