Intro to Coding with Blocks
Lesson 2 of 4 5 min +35 XP

Making Choices: If/Then

Programs that decide what to do.

What you'll learn

  • Understand a condition
  • Read an if/then block
  • Predict which branch runs
The umbrella decision

Every morning you run a tiny program: IF it's raining, THEN take an umbrella, ELSE leave it home. Computers make choices the same way, checking a condition and branching down one path or the other.

If this, then that

An if/then block checks a condition. If the condition is true, the blocks inside run. If it's false, they're skipped. This lets a program react differently to different situations.

True or false

A condition is a yes/no question, like 'is the score over 10?'. The answer decides which path the program takes.

Lab · Trace the path
  1. Imagine: IF score > 10, THEN play a sound.
  2. Set score to 12 — does the sound play?
  3. Set score to 5 — does it play?

What you should see: At 12 the condition is true so the sound plays; at 5 it's false so nothing happens.

Knowledge Check

+10 XP / correct

1. In an if/then block, the blocks inside run when the condition is…

2. A condition is best described as a…