MyLeoNes™

Yes-or-no choices — Computing, 4–6 years

A program can check one fact and choose what happens next. This simple idea makes games, stories and toys react to what is happening.

A question in a program

A program can ask a question with two useful answers: yes or no. If the answer is yes, it does one thing; if the answer is no, it does another, or waits. This lets a game notice what the player has done.

Why a program must check

A computer does not see a situation in the human way. It needs a small question that separates one case from another: Is the door open? Is the answer correct? Without such a check, the same action would happen every time, even when the situation changes.

A door in a game

Imagine a game with a locked door. First, the program checks: “Do you have the key?” If the answer is yes, it opens the door and shows the room. If the answer is no, it keeps the door closed and shows “Find the key”.

The almost-right question

A common mistake is asking a question that does not separate the cases, such as “Do you like the door?” That is reasonable because people can use feelings to decide things. A program needs something it can check clearly, such as whether a key is present.

Reactions in real devices

This idea appears when a washing machine checks whether its door is shut, or a lift checks which button was pressed. It also helps a toy make a sound when its sensor is covered. Each device reacts only to the checks it was designed to make.

Keep exploring

Other languages

Loading MyLeoNes™…