MyLeoNes™

Boolean logic and decisions — Computing, 14–17

Programs often need to choose what happens next. Boolean values and logical operators turn statements such as “password is correct” into precise decisions a program can test.

True or false

A Boolean value records one of two possibilities: true or false. A program can test a condition, such as age >= 16, and choose different instructions depending on the result; this is how software reacts instead of merely following one fixed list.

Why combine conditions?

Real decisions rarely depend on just one fact. “Allow entry” might require a valid ticket AND the correct date, while “show an alert” might need low battery OR high temperature. Logic operators express these rules without leaving the decision to guesswork.

A ticket check

Let has_ticket be true and age be 15. The rule is: enter if has_ticket AND age >= 16. The first condition is true, but 15 >= 16 is false; true AND false is false, so the program refuses entry. Changing age to 16 makes both conditions true.

AND is not OR

A common mistake is to use OR when every requirement must be met. It feels reasonable because OR sounds inclusive in everyday speech, but in programming “A OR B” succeeds when either one is true, while “A AND B” succeeds only when both are true. Writing the rule in words first helps.

Safety decisions

A lift can decide not to move if its doors are open OR its weight sensor is too high. A website can require a correct password AND a second verification code. These rules are useful because they make safety checks repeatable, though their conditions still need careful design.

Keep exploring

Other languages

Loading MyLeoNes™…