Coding with Conditions

What your child is learning
Earlier coding work is about sequences (do this, then this) and repeats (do this 4 times). In Grade 4 children keep building on both, including loops inside loops and actions that happen at the same time. Many also start meeting the next big idea, choices: a program can check something and do different things depending on the answer. In plain language, "if it is raining, take an umbrella, otherwise wear sunglasses". Programmers call the check a condition. Ontario's curriculum makes conditions a focus in Grade 5, so treat this guide as an early look rather than something a Grade 4 child must master.
With practice, children can read and write short programs that use conditions together with repeats, test them by tracing through step by step, and fix bugs. A condition is always either true or false, and often uses the comparisons children met in math: greater than, less than, equal to, even, odd.
You don't need a computer to teach any of this, and a lot of it works better without one.
Conditions build on the repeats in Coding with Loops, in Grade 3.
Why it matters
Conditions are what make a program behave like something intelligent. Every game, thermostat and traffic light uses them. Understanding them lets children go from "following instructions" to designing rules, which is real computational thinking.
The reasoning also supports math directly. Deciding "is this number even?" or "is the total greater than 20?" means applying a rule to a number, and tracing a program is a very good test of carefulness. Children who can find a bug in 6 lines of instructions are practising the same patience that checking a long division needs.
How to teach it
1. Notice choices in daily life
Ask for rules your household follows: "If the bin is full, take it out." "If it's after 8, brush your teeth." Write one on paper in a box with a YES and a NO arrow. That's a mini flowchart.
2. Write if and else clearly
if the traffic light is green
go
else
stop
Make sure your child understands that exactly one of the two branches happens each time. Never both, never neither.
3. Add a number condition
Try: "if the temperature is less than 10, wear a coat, else wear a T-shirt". Ask what happens at 4 degrees (coat) and at 15 degrees (T-shirt). What about exactly 10? 10 is not less than 10, so it's a T-shirt, which is a good moment to look closely at the exact wording of a condition.
4. Combine with a repeat
Repeat 6 times, counting n from 1 to 6:
if n is even, clap
else, stomp
The actions are: stomp, clap, stomp, clap, stomp, clap.
Have your child act it out, then trace it on paper in a table with one row for each value of n.
5. Put a repeat inside a repeat
Repeat 3 times:
take one step
repeat 2 times: clap
Each trip round the outer repeat is 1 step and 2 claps, so the whole program is 3 steps and 6 claps.
Act it out, then ask: if the outer repeat ran 4 times, how many claps? (8)
6. Trace a program that changes a number
Start with 6. Repeat 3 times: if the number is even, halve it, else add 1. Row by row: 6 is even, so it becomes 3. 3 is odd, so it becomes 4. 4 is even, so it becomes 2. The final value is 2.
7. Debug
Give your child a program with a mistake, such as "if the light is green, stop, else go". Ask them to run it in their head and say what goes wrong. Fixing programs is as important as writing them.
Common mistakes
- Doing both branches. Children read "if ... else ..." as a list. Use two coloured cards and reveal only one each time.
- Misreading the boundary. "Less than 10" and "10 or less" are not the same. Test the exact number.
- Skipping the trace. A child guesses the program's output. Insist on a table, one row per step.
- Checking the condition only once. Inside a repeat, the condition is checked each time round, using the current value.
- Thinking the computer can guess what you meant. It follows the words exactly. A bug is nearly always a rule that says something different from what its author meant.
Do this together
Card-sorting machine. Take a deck of playing cards and remove the aces and face cards, so every card is a number from 2 to 10. You are the "machine" and write a program on paper, such as "repeat for each card: if it is red, put it on the left; else if it is higher than 7, put it in the middle; else put it on the right". Your child plays the computer and follows the rules exactly, without using any common sense. Afterwards, discuss whether the program did what you wanted. Then swap: your child writes a program and tries to make it as tricky as possible while still being fair. Before you run each program, predict which pile will end up biggest, then count to find out.
Printable worksheet
18 questions, a picture warm-up and drawing tasks, with an answer key on its own page. Print it or save it as a PDF.
Every worksheet is on the printable worksheets page.
Ontario curriculum: Grade 4, Algebra, expectation C3 · official document · U.S. Common Core crosswalk