Introduction
15 minAt the end of last lesson you wrote a number in your book: what a 50-step staircase would cost you, dragged out block by block. It was somewhere over a hundred and fifty.
Today that number becomes four — and it stays four whether you build 5 steps or 500.
The block that does things again
The Loops drawer holds a block shaped like a mouth:
repeat
4times — do — …
Whatever you drop into its mouth happens again, and again, for as many times as the number says. Nothing else changes. The Agent does not learn anything new today; you simply stop telling it the same thing over and over.
Inside the mouth, or outside it
This is the whole lesson, and it is worth getting right before you touch the keyboard:
| Where a block sits | How often it runs |
|---|---|
| Inside the repeat's mouth | once for every count — 5 times, 50 times |
| Outside, above or below | once, whatever the number says |
So agent teleport to player belongs outside: you want the Agent to come to you once, at the start, not to jump back to you before every single block. Put it inside by mistake and the Agent returns to your feet each time round — it builds one block, fifty times, in the same spot.
Say it out loud
A good loop can be read as a sentence:
Come to me. Take 64 stone. Then, five times over: lay a block and step forward.
Compare that with last lesson's version, which was the same sentence with "lay a block and step forward" written out five times in a row. Same meaning. Far fewer words.
One number is now the size
Here is what you are really gaining. Last lesson, making the line longer meant dragging out more blocks. Today it means changing one digit.
That is the difference between a program you wrote and a program you can use.
Warm-up — instructions for a clap
Ask someone to write down instructions for clapping twenty times, and they will start writing "clap" twenty times and lose patience at about six.
Then ask for the short version. Everybody gives the same answer: "clap twenty times."
You have known how a loop works your whole life. Today you only have to find the block.
What you will be able to do
- Put a repeat block around work that was written out by hand.
- Decide what belongs inside a loop and what belongs outside it.
- Change the size of a whole build by editing one number.
- Rebuild last lesson's line, square, tower and staircase in a fraction of the blocks.
Basic
20 minFollow along on your own computer. Everyone should finish this part with the same working program.
Step 1 — Look at what you wrote last lesson
Open your line program from Lesson 2. It should look like this — nine blocks after the set-up, to lay five stone:
Count the place and move blocks. Nine. Now look at how many of them are the same two blocks, over and over.
Step 2 — Take the repeat block
- Press
Cand open your project. - Click the Loops drawer — it is green.
- Drag out a repeat 4 times block. Notice its mouth: it is open, waiting to be filled.
Step 3 — Put the pair inside
Pull one place on down and one agent move forward by 1 into the repeat's mouth, then delete the leftovers. Change the 4 to a 5.
Challenge 1
15 minThe square, in one loop.
In Lesson 2 you built a square outline by duplicating one side four times. Today you build it with a single repeat.
- Press
Cand start a new chat command calledsquare. - Bring the Agent to you and fill slot 1 with stone. Both of those go outside the loop.
- Use exactly one repeat block to build the outline of a square with sides of 4 blocks.
- Think about what one side needs, and what has to happen at the corner before the next side starts. All of that goes inside the mouth.
- The Agent must finish on the block it started from, facing the way it started.
- Go back to the world, type
square, then fly up and look down at it. - Now change the side length to 8 by editing as few numbers as you can, and run it again.
It works if: looking down you see a closed square outline with a hollow middle, the Agent is back where it began, and your program contains one repeat block and no duplicated sides.
Challenge 2
20 minA tower of any height.
Last lesson's tower was ten blocks tall and cost you twenty blocks of program. Make it cost four.
- Press
Cand start a new chat command calledtower. - Bring the Agent to you and fill slot 1 with stone.
- Use one repeat block to build a tower 10 blocks tall, then bring the Agent back down to the ground at the end.
- Run it and count the tower from a distance to check it.
- Now make it 30 blocks tall. Here is the rule: you may change one number only.
- Run it again and look up.
Step 5 is the real challenge. If bringing the Agent back down forces you to change a second number, that is a sign worth noticing — ask yourself what else could get it back to the ground.
It works if: typing tower builds a tower exactly 30 blocks tall with no gaps, and getting there from 10 took you a single edit.
Challenge 3
25 minThe staircase and the platform.
Build something you can actually climb, ending somewhere worth standing.
- Fly to a clear, flat piece of ground and land.
- Press
Cand start a new chat command calledlookout. - Bring the Agent to you and fill slot 1 with stone — 64 may not be enough, so take more.
- Using a repeat, build a staircase of 20 steps, each one block up and one block along.
- Then, using a second repeat, build a flat platform at the top, at least 5 blocks long, running on in the same direction.
- Go back to the world, type
lookout, and then walk up it on foot. No flying, no jumping.
It works if: you can walk from the ground all the way to the top and stand on a flat platform without flying or jumping once, and your program uses two repeat blocks and no duplicated steps.
Extra challenge
spare timeThe spiral staircase.
Your staircase runs away in a straight line and ends up a very long way from where it started. Real towers have stairs that wind.
- Open your
lookoutprogram and duplicate the staircase part into a new chat command calledspiral. - Add one single block inside the loop's mouth — and change nothing else at all.
- That one block should make the staircase turn a corner on every step, so it winds upward around itself instead of running off across the world.
- Run it, then walk up.
That is the whole task: one block, inside the mouth. If you find yourself adding a second, stop and think again about what makes the Agent face a new direction.
It works if: the staircase climbs in a square spiral that stays roughly above where it started, and you can still walk all the way to the top on foot.
Why this is the point of the lesson
A loop is not just a way to save typing. What you put inside the mouth decides the shape of everything that comes out.
You changed one block and a staircase became a tower. Next lesson you put a loop inside a loop, and one change turns a line into a wall.