Topics · Patterns & Equations
Code that decides
Code can ask a question and then do different things depending on the answer. Children read short programs, predict what they will do, change one thing and watch what follows, then write programs of their own.
Reading code is how you find out what a machine will do before you let it do it — a mathematical habit long before it is a computing one.
More ways into this idea
- Make it a gameRule MachineRead a rule, work out what changed, then make one work
- Test yourselfA fresh mixed set, whenever you likeExplanations after every question. Nothing is recorded.
Common sticking points
- The commonest one is expecting an IF to do everything inside it — the THEN part and then the ELSE part, one after the other. Exactly one of them ever happens, and running the rule with the steps showing is the fastest way to see it.
- The boundary case catches almost everyone: "greater than 20" does not include 20. If everything works except the number sitting exactly on the line, that is what has happened.
- A question INSIDE another question gets read as two questions in a row. The inner one is only ever asked when the outer answer was yes — which is exactly what makes three outcomes possible instead of two.
Try this together
Make up a rule together for something ordinary — how long someone gets on the swing, say. If nobody is waiting, five more minutes; otherwise, two more. Try it on four real situations and see whether it ever needs a second question inside the first. That is a conditional, and your child has just written one.
1–5 minutes, no materials to buy, nothing to hand in.
Ontario curriculum details
- C3.1Write code for mathematical situations
- C3.2Read and change code, including conditionals
Plain-language summaries. See the full curriculum for every expectation and the official source.