Idea 11of 23Builds onIF … THEN runs only on a yes
IF … ELSE picks one of two paths
How can one rule do two different things?
Today you'll discover
- what ELSE adds
- why only one path runs
- how to follow any number through
Think firstThe ticket machine: IF number > 20 … ELSE …
What does the machine output for the ticket number 12?
Decide first, then press Next. Follow the thick line: it takes one path only.
A flowchart of the ticket machine: a diamond asks Is number > 20?. The yes path, marked THEN, leads to ADD 5; the no path, marked ELSE, leads to MULTIPLY BY 2. 12 travels the ELSE path to 24, then 24 travels the THEN path to 29. Along the bottom: 12 no to 24, 24 yes to 29, 4 no to 8, 30 yes to 35. The last step asks what IF number > 50 THEN SUBTRACT 10 ELSE ADD 10 outputs for 30.
See the whole ideathe big idea and the key word, in one place
The big idea
IF … ELSE runs THEN on a yes and ELSE on a no, never both.
Compare themIF … THEN has one path, and on a no it does nothing. IF … ELSE has two paths and always runs one of them.
Easy to get wrongThe machine never runs both paths. 12 gives 24, not 24 + 5.
Key word
- ELSE
- the part of an IF that runs only when the condition is false
Ready to use it?
- Say which part of an IF … ELSE runs for a number, and what it outputs.