🔗 Logical Operators

5th Grade 💻 Coding

`and`, `or` and `not` are logical operators: they combine conditions or flip them. `and` — both are true; `or` — at least one is true; `not` — the opposite.

Free · US Letter · no sign-up
Google Classroom Save to Pinterest Email me

True and False gives False, because and needs both sides to be true. True or False gives True, because or is happy with just one. not True gives False. You can build complex conditions out of these: “If you have a ticket and it’s before eight o’clock, you can go in.”

Here’s a confusing case: in everyday English, “or” sometimes means “one or the other, not both” (“Tea or coffee?”). In programming, or is also true when both sides are true. It’s a good idea to check every complex condition with a small table of all the possibilities.

For example

  • In a game: if lives > 0 and time > 0: — you keep playing only if you have both lives and time left.
  • Recess: if it’s raining or it’s too hot outside, everyone stays indoors.

📌 Remember: and — both. or — at least one. not — flip it.

Quick quiz

  1. What does True and False give?

  2. What does True or False give?

  3. What does not do?

🔎 Ask Thinkapedia another question