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
- Imagine: IF score > 10, THEN play a sound.
- Set score to 12 — does the sound play?
- 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.