Introduction to Programming
No programming language required. First you learn to think like a programmer, giving the robot commands and learning algorithms live. Then you choose the path that suits you.
Which command gets the robot to the star?
What a program is and how it works
How a computer "thinks"
A computer is very fast, but it does not think on its own. It only carries out the command you give, in the order you give it, exactly. It adds nothing, and leaves nothing out.
That is why a programmer's main job is to give the machine precise, step-by-step commands. If you say "take the apple", it won't understand. You have to spell out every step: "move forward, move forward, take the apple".
The robot below works just like a computer. Its program (the list of commands) is on the left, and it runs on the right. Each command lights up and runs in turn:
Algorithm = a sequence of steps
An algorithm is a precise sequence of steps for getting something done. You use them every day: brewing tea is an algorithm too. What matters is the order of the steps. Break the order and you break the result.
Your first program
Now it's your turn. Guide the robot all the way to the apple. Click the commands below to build a program, then press Run. The robot runs your program top to bottom, exactly.
Tip: watch which way the robot is facing. Use the "turn" commands to change its direction.
Module test
Answer at least 3 of the 4 questions correctly to unlock the next module.
Algorithms and flowcharts
Breaking a problem into steps
The secret to solving any big task is to break it into small, precise steps. Getting a robot out of a maze, or building a website, both start by splitting the work into stages.
Programmers often draw these steps as a flowchart: each action is a box, arrows show the order, and a diamond represents a condition (yes or no). The flowchart below shows how the steps run one after another:
Planning ahead for the robot
Now a bigger maze. To get the robot to the apple, plan ahead: where to go straight, where to turn? Think through each turn in advance, that is what planning an algorithm means.
Module test
Answer at least 3 of the 4 questions correctly to unlock the next module.
Variables
Storing a value: the box
A variable is a named box where a value is stored. You can put a number, text, or a yes/no (boolean) value in it, and change it as often as you like.
Try the "score" box below. When you click the buttons, the value inside changes, but the name of the box stays the same:
The robot counts apples
Now the robot collects several apples. Each time it picks one up, the apple variable goes up by 1, just like a counter. Teach the robot to collect all three apples and watch the counter:
Module test
Answer at least 3 of the 4 questions correctly to complete the module.
Conditions (if...)
The robot makes a decision
So far the robot has followed commands blindly. But real programs can look and make decisions: "if something is true, do this; otherwise, do something else". This is called a condition.
An everyday example is a traffic light: "if the light is red, stop; if it's green, go". The robot also "sees" what's ahead and picks its path accordingly. Below, two cases light up in turn:
Controlling with a condition
Now the robot can land in two different situations, but it doesn't know in advance which one. Build a single program that works in both situations. The trick: use the "if there's a wall ahead, turn right" condition.
Use the "Situation A / B" button above to switch between the cases. One program (without changing it) must solve both.
Module test
Answer at least 3 of the 4 questions correctly to unlock the next module.
Repetition (loops)
Doing one thing many times
Sometimes you need to write the same command over and over. A loop (repetition) shortens this: "repeat 6 times: forward" means run "forward" 6 times.
Below, the two give the same result, but the loop is much shorter:
The robot below moves using a loop. The loop counter goes up with each repetition (for example 1/5, 2/5 ...):
Controlling with a loop
Guide the robot to the apple, but the path is long. Instead of writing "forward" many times, use a loop: click the "repeat" button and adjust the number with − / +.
Module test
Answer at least 3 of the 4 questions correctly to complete the module.
Functions
Giving commands a name
Sometimes you use a group of commands over and over. If you bundle them under a single name, you get a function. After that you just "call" the name and the whole group runs.
An everyday example: say "brew tea" and every step happens on its own. Below, the stairs() function gives a name to the motion of climbing one "step":
The robot below climbs the steps by calling stairs(). When it's called, the function block lights up:
Controlling with a function
The robot needs to climb a staircase. Every step is the same motion, that is stairs(). Instead of rewriting four commands each time, call the function. Click the "stairs()" button a few times and take the apple.
Module test
Answer at least 3 of the 4 questions correctly to complete the module.
Errors and debugging
What an error is and how to find it
Every programmer makes mistakes, and that's normal. When a program stops working or gives a wrong result, there is an error (in English, a "bug") in it. The process of finding and fixing an error is called debugging.
If the robot doesn't reach the apple or bumps into an obstacle, it means there is an error in the program. A good programmer doesn't panic, but finds the error with the following steps:
Find and fix the error
The program below has an error: the robot hits an obstacle instead of reaching the apple. First use "Run" to see where it stops, and check with "Step" if needed. The error is one extra "forward" in the first row. Click the extra command to delete it and run again.
Module test
Answer at least 3 of the 4 questions correctly to complete the module.
It gets harder stage by stage
10 mazes, each harder than the last. Solve each stage to unlock the next. Here you use all the commands you have learned.
Build your own maze
No grades here, no limits. First, in Build maze mode, click the cells to place walls, apples and the robot's position. Then switch to Programming mode, control the robot with all the commands you have learned, and solve the field.
For completing the full course
Enter your name, view your personal certificate confirming that you finished the "Introduction to Programming" course, including the 10-stage challenge, and download it as an image.