From circuits to code: what logic gates teach you before programming
People often think programming starts with learning a language. In fact, a good part of the job is writing conditions: “if this and not that, then…”. Those conditions are logic gates. Playing with them as circuits first gives you a head start.

A condition is a gate
Take two lines of Python, a language many students learn at school:
if raining and not umbrella:
stay_inside()
These two lines contain two logic gates. The not is a NOT gate: it inverts “I have an umbrella”. The
and is an AND gate: it only lets things through if both conditions are true. In our game you would draw exactly
this circuit: the “umbrella” input goes through a NOT gate, joins the “raining” input in an AND gate, and the lamp lights up
when you should stay inside. The program and the circuit have the same truth table.
True, false, 1 and 0
In a circuit we talk about 1 and 0; in a program, about true and false: True and False in
Python, true and false in JavaScript. It is the same thing. Operators change their names from one
language to another, but not their meaning: AND is and in Python and && in JavaScript, OR
is or in Python and || in JavaScript, NOT is not in one and ! in the
other. A student who has played with gates recognises straight away what they are reading.
The truth table, your first testing habit
When a condition gets complicated, mistakes creep in quickly. A careful programmer then does what the game does: list every possible combination and check what the condition gives for each one. With two conditions there are four cases; with three, eight; with four, sixteen. This habit is at the heart of software testing: check every case, not just the one that comes to mind. Anyone who has filled in truth tables already has it, without knowing.
De Morgan's laws, to simplify
A condition can be written in several ways. “Neither tired nor ill” can also be said “not tired and not ill”, or “not (tired or ill)”. That is one of De Morgan's laws, and programmers use it every day to make a condition easier to read. In the game you can see it: two different circuits that light the lamp on exactly the same rows do the same thing. Our page on the truth table gives an example.
XOR, a handy tool for programmers
The XOR gate (exclusive OR) outputs 1 when its two inputs are different. In programming it turns up often: to check
whether two values differ, to toggle a setting (one click turns it on, the next turns it off), and in encryption, where a
message is mixed with a key using XOR, and the same XOR with the same key gives back the original message. In Python it is
written ^. The details are on the XOR gate page.
And what about arithmetic?
A computer adds up with gates. To add two bits, two gates are enough: an XOR gives the units digit and an AND gives the carry. 1 + 1 makes 0, carry 1: the XOR of 1 and 1 is indeed 0, and the AND is indeed 1. The last of the 10 free circuits of our game has you build exactly that adder. Chain such circuits together and you can add whole numbers, then multiply, then do everything else.
Debugging means finding the broken gate
A program that gets things wrong often has a badly written condition somewhere. In Bit's Journey, our longer logic game, one chapter asks you to find the gate that a careless repairman replaced with the wrong one: that is exactly the job of a programmer hunting for a bug. The chapter before it turns the problem around: the gates are already in place, and you have to find the position of the switches that lights the lamp. That is what a programmer does when looking for the exact case that triggers an error.
There is no need to wait for the last years of secondary school: a younger student who can read a truth table will approach the conditions in their first program without fear.