Sequencing with Blocks

Have you ever used Scratch or ScratchJr on a tablet, or driven a little floor robot like a Bee-Bot across the carpet? When you code with those, you don't type long words. Instead you grab colourful instruction blocks and snap them together, one under the next, like LEGO or train carriages.

Each block is one little order: move, meow, turn, jump. When you press the green flag, the computer reads your blocks from the top and does them one after another, all the way down to the bottom. That stack of blocks, done in order, is called a program — and putting the blocks in the right order is called sequencing.

A stack of blocks for the cat

Here is a tiny Scratch-style program for a cat sprite. Read it like a list, from the top going down. Press play and watch each block light up in turn — that is exactly the order the cat does them in.

First the cat moves, then it meows, then it wiggles. The blocks are snapped in that order, so the cat does them in that order. Nothing jumps the queue!

Blocks are just steps in order

A grown-up coder might type their steps as words instead of snapping blocks — but it is exactly the same idea. Each line is one block. The computer reads them from the top and does them one after another. Press Run and watch the words pop out.

console.log("Move"); console.log("Meow"); console.log("Wiggle");

The words come out in the same order as the lines, just like the cat's blocks: Move, then Meow, then Wiggle. Blocks or words — a program is always steps in order, top to bottom.

Drive the floor robot to the treasure

Now let's snap blocks for a floor robot, like a Bee-Bot. It sits on a grid of squares and only knows three blocks: forward, forward, and turn. We stack them in order to lead it to the treasure chest. Press play, or step through one block at a time.

So the whole program is: forward, forward, forward, turn, forward, forward. Stack the blocks in that order and the robot reaches the treasure every single time.

The order is the program

Here is the big secret: the same blocks in a different order make a different program. If we swap the cat's first two blocks, the cat meows before it moves — a totally different little show!

The blocks run in the exact order you stack them, from top to bottom. Swap two blocks and the sprite does the wrong thing. Put meow above move and the cat squeaks while it is still standing still. Tell the floor robot to turn before it goes forward and it spins off to the wrong square, missing the treasure completely. The computer will not fix it for you or guess what you meant — it just does the blocks in order, muddle and all. That is why we say: the order is the program. Getting the right blocks isn't enough — you have to stack them in the right order.

When you are little, typing lots of tricky words is slow and easy to get wrong — one missing dot and the whole program breaks! Blocks are much friendlier: you can only snap them together in ways that make sense, the words are already spelled for you, and you can see your whole program as a colourful tower. That is why apps like ScratchJr and Scratch were invented — so anyone can build a real program just by snapping. When you're older you'll type your blocks as words, but the idea never changes: steps in order, top to bottom.

The green flag means "GO!" The moment you tap it, the computer jumps to the top block, does it, then slides down to the next block, does that, and keeps sliding down until it runs out of blocks. It is just like a finger tracing down a shopping list. It never starts in the middle and never reads the bottom block first — always top to bottom, one block at a time.