MyLeoNes™

Conditionals: making choices — Computing, 11–13 years

A program can choose what to do by checking whether something is true. Computing, 11–13 years.

A program can choose

A conditional lets a program take different paths. It checks a question, such as “is the score at least 10?”, and runs one set of instructions if the answer is yes and another if it is no.

Why choices are needed

Real tasks do not always have the same answer: a game may need to react to a missed shot, and a website may reject an empty password. Conditionals solve this problem by turning changing situations into clear choices.

Checking a ticket

Suppose a museum ticket costs 8 euros and a visitor has 6. First compare 6 with 8. The condition “money is at least 8” is false, so the program displays “You need 2 more euros” instead of printing a ticket.

The boundary mistake

A common mistake is using “more than 10” when the rule really means “10 or more”. This feels reasonable because everyday speech often blurs the boundary, but a computer treats 10 and 11 as different cases, so the exact comparison matters.

Choices outside code

Conditional thinking appears in automatic doors, traffic lights and online forms. Each system checks information and responds: open if someone is near, show green if it is safe, or warn if a required box is empty.

Keep exploring

Other languages

Loading MyLeoNes™…