Chapter 04

True or False? — Simple Decisions

Primary
At a glance
Core ideaA decision checks a true/false question and then picks a path.
Key termIF / THEN / OTHERWISE — the fork in the road.
You can…Chain simple yes/no tests to sort things and choose actions.
Watch outOnly one branch runs — the true one or the false one, never both.
Theory

Some questions only have two possible answers: yes or no. In computing we call these true and false. A computer can check a true/false question and then choose what to do next based on the answer — this is called making a decision.

We often say it like this: "IF it is raining, THEN take an umbrella. OTHERWISE, wear sunglasses." The IF checks something true or false; THEN and OTHERWISE are the two different paths you can take.

START Is it raining? TRUE FALSE Take an umbrella Wear sunglasses
An IF checks one true-or-false question, then the program follows only one of the two paths.
Explanation

Decisions let a program behave differently depending on what is happening, instead of always doing the exact same thing. A traffic light "decides": if the light is red, cars stop; if it's green, cars go. Without decisions, every program — and every traffic light — would have to do the same thing forever, no matter what was actually true.

Big idea. A decision is just a fork in the road: check something true-or-false, then follow one path or the other.

Practical

Activity: The Sorting Game. Gather a pile of toys, fruit, or drawn pictures. Ask one true/false question at a time and sort into two piles: "IS IT RED?" — everything red goes left, everything else goes right. Then take the "red" pile and ask a second question: "IS IT ROUND?" You have just built a chain of decisions — exactly what programs do when they check more than one thing.

Q&A
Q1 What does "true or false" mean?

It means a statement can only be one of two things: correct (true) or not correct (false). "This apple is red" is true or false depending on the actual apple.

Q2 What is an IF used for?

An IF checks whether something is true, and only does the step that follows it when the answer is yes. It lets a set of instructions react differently depending on what is actually happening.

Q3 Can a decision check more than one thing?

Yes! You can chain decisions together, like the sorting game: first ask "is it red?", and only for the red pile, ask "is it round?" Each question narrows things down further.

Concept mind map

How the ideas connect

Every key idea in this chapter, branching from the core concept — use it to see the whole picture at a glance.

IF conditionTHEN actionOTHERWISE actiontrue or falsepick a pathchained testsTrue or false decisions
Infographic

The key facts, visualised

Condition
A yes/no question the computer checks, answered true or false.
IF / THEN
If the condition is true, then do this action.
OTHERWISE
The path taken when the condition is false (the else branch).
Fork
A decision splits the flow into two possible paths.
Solved examples

Worked problems, step by step

Follow each solution line by line, then try to reproduce it on paper before moving on.

Example 1IF it is raining THEN take an umbrella OTHERWISE wear a hat. It is raining. What happens?

  1. The condition "raining" is true.
  2. So take the THEN path.

Example 2Sort a number: IF number > 10 say "big" OTHERWISE say "small". Number is 4.

  1. Check 4 > 10, which is false.
  2. Take the OTHERWISE path.
Practice problem set

Now you try

Work each one out first, then tap to reveal the worked answer.

1What is a decision in a program?
It checks a true/false question (a condition) and then picks a path based on the answer.
2What does IF / THEN / OTHERWISE mean?
IF a condition is true THEN do one action, OTHERWISE do a different action.
3IF the light is green THEN go. The light is red. What happens?
The condition is false, so the "go" action does not run.
4How can you sort things with decisions?
Chain simple yes/no tests, sending each item down the true or false path that fits it.
5Can a condition ever be both true and false?
No. At the moment it is checked, a condition is exactly one of true or false.
6What is the OTHERWISE (else) branch for?
It gives the action to take when the condition turns out to be false.