Building Blocks of All Programs

Every program ever written — games, apps, websites — is built from just 3 ideas.

1️⃣

Sequence — Do things in order

A computer follows steps one at a time, in order. Like a recipe — you can't frost a cake before you bake it.

2️⃣

Iteration — Repeat an action

Instead of writing the same step 100 times, a loop does it for you. Run one lap, then do it again and again.

3️⃣

Decision — Choose a path

Programs ask questions and take different actions depending on the answer. Is it raining? Bring an umbrella!

Click Next to explore each one interactively.

Sequence
do things in order
A computer follows steps one at a time, in order. You can't bake a cake before you mix the batter!
🎂
Press Run to start cooking!
Crack an egg
Mix the batter
Bake the cake
Press Run to start cooking!
+ show code (Python)
crack_an_egg() mix_the_batter() bake_the_cake() # Each line runs after the one above it. # You can't bake before you mix!
Iteration
same thing, over and over
Run one lap — then do it again, and again. The same action repeats 5 times. That's a loop!
START laps 0/5
1
2
3
4
5
Press "Run loop" to start!
+ show code (Python)
for lap in range(5): run_one_lap() # run_one_lap() runs 5 times. # Same action, repeated by the loop. # Change range(5) to range(100) — # now it runs 100 times. You only wrote it once!
Decision
choose a path
The computer checks a condition and takes a different action depending on the answer. Pick the weather below to see what happens!
Is it raining?
🌂
Bring umbrella
😎
Wear sunglasses
Choose the weather to see what happens
+ show code (Python)
raining = check_weather() if raining: bring_umbrella() else: wear_sunglasses() # The program checks the condition, # then runs only ONE of the two paths.
Slide 1 of 4