If-then statements for kids: how to explain conditionals

What a condition is in an algorithm, everyday if-then examples, unplugged games, common mistakes and a matching Looponi lesson for children aged 6 and up.

Updated:

The “Guess what I'm thinking of” game in Looponi: switches with YES/NO questions lead to different animals

A program that always does the same thing gets boring fast. It gets interesting when the program can check something and choose. That is what an if-then statement, or conditional, is for. In plain words it says: “if this is true, do that, otherwise do something else”. Children use this logic every day. They just don't have a name for it yet.

Conditionals in plain words

A condition is a question with only two possible answers: YES or NO. “Is it raining?” “Is the number bigger than 5?” “Is the wagon red?” The program asks the question, and the answer decides which way it goes next.

In a flowchart a condition is drawn as a diamond. One path goes in, two paths come out: one labelled YES, the other NO. Our guide to flowcharts for kids shows the other shapes too.

Three rules are worth repeating from the start:

  1. The question needs a YES or NO answer. “What's the weather like?” is not a good condition. “Is it raining?” is.
  2. The program takes one path only. Never both at the same time.
  3. Both paths have to lead somewhere. If we forget what happens on NO, the program doesn't know what to do.

Everyday examples

Start with situations children know from home and school:

The last example matters because it has a number and a boundary. What happens if you have exactly £10? “More than 10” means 11, 12 and up. With exactly £10 the answer is NO. Cases right on the boundary are worth practising on their own, because that is where children and adults make the most mistakes.

Unplugged games

1. A track that splits

Make a path on the floor with masking tape that forks at one point. Put a card with a question at the fork, for example “Are you wearing something blue?” The child walks the path, answers at the card and turns left on YES, right on NO. A different surprise waits at the end of each branch. Then swap roles and let the child write the question.

2. Sorting blocks

Give the child a box of blocks in several colours and two tubs. The rule: “If the block is red, put it in the left tub. Otherwise, put it in the right tub.” The child follows the rule like a program, one block at a time. Then change the condition to “If the block is bigger than my thumb”. Some blocks will be hard to judge. That opens a good conversation: a condition has to be clear.

3. The robot with a secret rule

The adult plays a robot with one secret rule, for example “If you show an even number of fingers, I clap. If it's odd, I stomp.” The child holds up fingers and watches the robot. The goal is to guess the rule. This trains thinking backwards: from what the program does to the condition inside it.

4. Guess the animal

The child thinks of an animal. The adult may only ask YES/NO questions: “Does it fly?”, “Does it live in water?”, “Is it big?” Draw each question on paper as a diamond with two arrows. After a few rounds you have a question tree on the table: several conditions in a row.

5. Which coat today?

Draw two diamonds, one under the other. The first asks “Is it cold?” YES leads to the winter coat. NO leads to a second diamond: “Is it raining?” YES gives the raincoat, NO the hoodie. The child tests the chart with a few kinds of weather: frost, rain, sunshine. This is a first step towards nested conditions.

Common mistakes

What it looks like in Looponi

In Looponi a condition is a diamond-shaped switch. The token, Dot the little engine, reaches the switch and turns towards YES or NO.

In the lesson “Big load or small load” on the Little Ones track, the warehouse asks how many crates there are, and the switch asks: “over 5?” On YES a crane lifts the crates, on NO they go by cart. The child lays both tracks: from YES to the crane and from NO to the cart, then connects them to the last station. Before the run, the child predicts which way Dot will go with exactly 5 crates. Then they watch the run and read the explanation: 5 is not more than 5, so the cart goes. The boundary from the section above is practised directly. In the task the child lays the tracks again, and the program is tested with several numbers, including 5 and 6.

Earlier on the same track there is a simpler lesson with coloured wagons: red ones carry presents to the left, blue ones carry balloons to the right. Older children in the Decisions module write conditions with numbers, for example checking whether a number is even. In the game “Guess what I'm thinking of”, Byte asks YES/NO questions and tries to guess the animal the child has in mind.

What age is right?

Simple if-then rules with colours and pictures make sense to most children aged 6 to 7. Conditions with numbers and boundaries (“more than”, “at least”) usually fit from 7 or 8, once the child compares numbers with ease. Several conditions in a row and nested conditions are better from about 9 or 10. Our guide on what age to start coding has more on this.

Frequently asked questions

What is an if-then statement?

It is a place in a program where the program asks a YES/NO question, and the answer decides what happens next. It reads as “if…, then…, otherwise…”.

How do I explain conditionals to a 7-year-old?

Start with situations they know: if it is raining, we take an umbrella; if not, we go without one. Then play a movement game where the child picks a path after answering YES or NO.

What is the difference between a condition and a loop?

A condition picks one of two paths and the program moves on. A loop goes back to an earlier step and repeats it. Many loops contain a condition that decides when to stop.

Read next

All guides →