TwiddleLab / Code / How a Programmer Thinks
Instructions, Exactly
What you will learn
- An algorithm is a list of exact steps that gets a job done.
- The steps run in order, one at a time: a sequence.
- A mistake in the steps is a bug. The computer does what you said, not what you meant.
How the lesson goes
You'd just walk to the star. The robot can't.
It doesn't know what "get the star" means. It only follows its blocks. Where will it stop? Tap a square.
Run it, one block at a time.
Press Step. The glowing block is the one running now.
Fix it with one tap.
Delete the block that sends the robot into the wall, then press Run.
What you just did has names.
An algorithm is a list of exact steps that gets a job done. These blocks are one.
The steps run in order, one at a time, top to bottom. That is a sequence.
A mistake in the steps is a bug. Here it was one extra forward.
Programmers write the same steps as text. Each block has a Python twin, like forward().
Your turn: get the robot to the star.
Add blocks, then press Run. Up to 10 blocks.
Game: grab the coin, then reach the star.
Use as few blocks as you can. Par is 10.
Surprise: your program meets a flipped maze.
Run your blocks from before in both mazes.
Next lesson: Variables Are Boxes · Part of the course: How a Programmer Thinks
Lessons are interactive and need JavaScript. Turn it on to play them.