If this, then that
Snowing? Pheran and gumboots. Road closed? Bus at the main stop. Otherwise, walk. Muteeb's mother never repeats herself — she gave him rules.
- Turn everyday rules into if-then
- Build a Scratch maze that reacts to walls
- Find out what a program really "sees"
If this, then that
Snowing? Pheran and gumboots. Road closed? Bus at the main stop. Otherwise, walk. Muteeb's mother never repeats herself — she gave him rules.
- Turn everyday rules into if-then
- Build a Scratch maze that reacts to walls
- Find out what a program really "sees"
Story
If it is snowing, then wear your pheran and gumboots. If the road is closed, then wait for the school bus at the main stop. Otherwise, walk the usual way.
Learn it
Muteeb's mother gave him rules with conditions: if it is snowing, then wear the pheran. Every morning he checks the condition and decides for himself. A program does the same. It cannot see the weather, but it can check a condition, something that is either true or false, and choose what to do. That is how a program makes decisions without a person telling it each time.
Words to know
a question with a true or false (yes or no) answer, like "Is it snowing?" or "Is the sprite touching black?"
do something only when the condition is true.
two paths: one for when the condition is true, and the else path for when it is false.
a drawing of steps. A question is drawn as a diamond, with a Yes arrow and a No arrow.
a loop that never stops, so the program keeps checking its conditions.
Step by step: a kettle that decides
An electric kettle has one rule:
forever
if water is boiling then
switch off
else
keep heating
- The condition: is the water boiling? It can only be true or false.
- True: the kettle switches off.
- False: the else path runs, and it keeps heating.
- Forever: it keeps checking, so it notices the moment the water boils.
In Scratch the same shape looks like if <touching color [black]?> then … else …, inside a
forever loop.
Many if–thens in a row make a decision tree (Lesson 3.4), which is how many simple AI systems decide: Is the apple red? Is it bigger than 7 cm? Are there spots?
🕌 From our heritage
Remember al-Khwārizmī from Lesson 1.1? In Baghdad, around 825 CE, he wrote a book showing how to calculate with Indian numerals, step by careful step. Translated into Latin as Algoritmi de numero Indorum, his name became our word algorithm. (His other famous book, on al-jabr, gave us the word algebra.) The step-by-step rules you are building in Scratch today are that same idea, 1,200 years later.
Sources: al-Khwārizmī, Kitāb al-Ḥisāb al-Hindī, c. 825 CE, known in Latin as Algoritmi de numero Indorum; and Kitāb al-Mukhtaṣar fī Ḥisāb al-Jabr wa'l-Muqābala, c. 820 CE.
Careful: an if block checks only at the moment the program reaches it. Put it inside a
forever loop, or it checks once and never again. And the computer does not know what a wall
is, only its colour: paint the goal black and the sprite treats it as a wall.
Your missions
Maze and controls
pairs8 min- 1
Click the Stage, then Backdrops → Paint. Draw thick black walls and a small green goal box.
- 2
Pick a small sprite (set size 30). Add four scripts:
when [right arrow] key pressed → change x by 5, and the same for left (x by -5), up (y by 5) and down (y by -5).
Add the decisions
pairs10 min- 3
Under when green flag clicked:
go to x: (start x) y: (start y), then a forever loop holding two rules:if <touching color [black]?> then say [Ouch! Wall!] for 0.5 seconds go to x: (start x) y: (start y) if <touching color [green]?> then say [I made it!] stop [all]Use the eyedropper in the colour box to pick your exact colours.
- 4
Predict: what will happen when you steer into a wall on purpose? Then try it.
Only you can see this - 5
Play your partner's maze. Can you reach the goal?
Add an if-else: if the sprite touches blue water, it says Splash! and slows
down; else it moves normally.
No laptop today?
Draw a grid maze on paper. Your partner is the sprite and follows your rules out loud: "If the next square is a wall, then stay and say Ouch." Then draw your rules as a flowchart with diamond-shaped question boxes.
Debate it
A school gate machine lets a student in if they show an ID card. One day a child forgets their card. It is freezing outside and the machine says No. Should a machine's rule ever be broken? Who should be able to say "let them in anyway"?
Check yourself · practice, not a test
In the app, students answer these one at a time and each answer is checked straight away. It's practice, never a mark — anything they miss comes back later for another go.
1.A condition in a program can only be true or false.
TrueFalse2.What does this rule do? if <touching color black?> then go to start
- AIt paints the wall black
- BIt sends the sprite back to the start when it touches a black wall
- CIt stops the program forever
- DIt moves the sprite 5 steps
3.Put these steps of a morning rule in order:
- 1If yes, wear gumboots
- 2Look outside
- 3Check: is it snowing?
- 4Walk to school
4.An if-then-______ block gives the program a second path for when the condition is false.
If this, then that: conditions let a program decide.
Typing practice
Practise the arrow keys and space bar. You will steer a sprite with them today.
- typing.com: Beginner → Space bar lessons, then free practice
- Then type this sentence twice, with no mistakes:
if it is snowing then wear boots
Written and designed by Faizan Ayoub. © 2026 Faizan Ayoub. All rights reserved.