Skip to the page

All posts

What an if-statement looks like to a 6-year-old

Critter Meadow: the fox and a friend out in the meadow by the pond

“If” is one of the first words programmers learn, and one of the most important. A program that checks before it acts can make decisions. Here’s how a six-year-old meets that idea in Game Creators Club, with no typing and almost no reading.

Start with a gate that’s too easy

In the If lesson, there’s a gate in a fence across Critter Meadow, a key up by the north wall, and a pinwheel past the gate. The child plays the level and notices something odd: the gate opens when you bump it, key or no key. The key is pointless.

Then they open the gate’s brain. The rule says WHEN bumped, DO open. Nothing else. The child can see why the key doesn’t matter: the rule never asks about it.

Guess before you try

Before they fix anything, the game asks them to predict. If we add a check for the key, and you bump the gate with no key, will it open? Kids answer, and then watch a replay that walks straight at the gate with no key. Guessing first turns the fix into an experiment rather than a chore.

The fix is one tile

To fix it, the child adds an IF tile: IF you have 1 key or more. The rule now reads WHEN bumped, IF key 1+, DO open. That’s an if-statement, built out of three pictures.

When the rule runs, the IF tile shows a little lamp. Green means the check passed, and it says what it found: “has 1”. Red means it didn’t, so the DO doesn’t run. A child can watch the lamp to see exactly why the gate did or didn’t open.

The game checks it both ways

The fix counts only when the gate stays shut with no key and opens with one. Testing both sides is real debugging practice, and the game does it for them, so a child learns that a fix has to work every time, not just once.

Then they make their own

In Make, there’s a gate in the doorway of their own flower garden, and it opens on any bump. This time nobody planted the fix: the child adds the IF themselves, so the gate opens only with 3 berries.

A couple of lessons later comes Otherwise: if not, do this instead. By then “if” isn’t a word in a book. It’s something they have used to make a game do what they wanted.

Fix a game’s rule yourselfTry it

More from the blog