computer4kids is now ComputerLeap. Same free lessons, same team. Read why we changed our name

← All lessons · 🧑‍💻 Coding Academy

🔀

🎓

⏱ 10 min

Free

If This, Then That

Computers can make choices! Learn how “if” helps code decide what to do.

🎯 What you will learn

  • An “if” helps the computer choose
  • If something is true, do one thing
  • Otherwise (else), do another

👋 Let’s get started!

IF it is raining, THEN take an umbrella ☂️. Otherwise, wear sunglasses 😎. You make choices like this all day! Computers can make choices too, using IF.

🪜 Step by step

1. ❓ Ask a question

An if starts with a question that is yes or no: Is it raining? Is the light red?

2. ✅ If yes…

If the answer is yes, the computer does the THEN steps.

3. ❎ Else…

If the answer is no, the computer does the ELSE steps instead.

🧪 Try it!

Read the code, guess what it prints, then press 👀 Show output.

Robo crosses the street

if light is 🔴:
    🛑 stop
else:
    🚶 walk

🎨 Unplugged activity

🚦 Play Red Light, Green Light! IF the light is red, freeze. ELSE, walk. You are running an if program with your body!

Get dressed for the weather

look outside 👀
if it is cold:
    🧥 wear a coat
else:
    👕 wear a t-shirt

📖 Key words

Tap a card to flip it over!

If
Checks if something is true ❓
Then
What to do if it’s true ✅
Else
What to do if it’s not true ❎

Knowledge Check Quiz

  1. IF it is night, THEN…
  2. What does “else” mean?
  3. Can computers make choices with if?
← Previous lesson
Next lesson →