Back to Mathematical Foundations
IntermediateTeenagers

Introduction to Logic

Logic is the foundation of all computing. Computers think in terms of 'true' and 'false'.

We use logical operators to combine these true/false values.

AND: The 'AND' operator is true only if BOTH conditions are true.
(Is it daytime?) AND (Is the sun out?)
If both are true, the result is true. If either is false, the result is false.

OR: The 'OR' operator is true if AT LEAST ONE condition is true.
(Do I have a cat?) OR (Do I have a dog?)
If you have either, or both, the result is true. It's only false if you have neither.

NOT: The 'NOT' operator simply flips the value.
NOT (true) is false.
NOT (false) is true.

This is how computers make complex decisions.

If-Else Statement

Check if the `number` is greater than 0. If it is, print "Positive". Otherwise, print "Not Positive".