Logical Operators Formula

Logical operators are operators that combine or modify boolean expressions: AND (true only when both operands are true), OR (true when at least one operand is true), and NOT (reverses a boolean value from true to false or vice versa).

The Formula

AND: T∧T=T; OR: F∨T=T; NOT: ¬T=F

Ask yourself: Is one condition built by joining true/false tests with AND or OR, or by flipping one with NOT?

Quick example

x > 0 AND x < 10 is True only when x is strictly between 0 and 10, which for whole numbers means 1 to 9 (e.g., x=5 is True, x=11 is False).

What this formula means

Operators that combine or modify boolean expressions: AND (true only when both operands are true), OR (true when at least one operand is true), and NOT (reverses a boolean value from true to false or vice versa).

Two light switches wired one after the other light the bulb only when both are on: that is AND. Wired side by side, either switch alone lights it: that is OR. NOT is a switch mounted upside down. The picture predicts every two-input case, but it says nothing about the order a program follows in a long mix of operators.

Formal view

Logical operators on boolean values: conjunction A∧B (AND), disjunction A∨B (OR), negation ¬A (NOT). They satisfy De Morgan's laws: ¬(A∧B)=¬A∨¬B and ¬(A∨B)=¬A∧¬B.

Worked examples

Example 1

medium
Evaluate A AND NOT B OR C for A=True, B=True, C=False, using standard precedence.
Show solution

Answer

False

First step

1.
NOT B = NOT True = False.

See the full worked solution + why-it-works coaching

SetupKey insightWhy it worksCommon pitfallConnection

Free: full solutions on 3 topics a day. No card.

Every topic, every day: the Family plan

Example 2

medium
Use De Morgan to rewrite: NOT(x>0 OR y>0).

Example 3

medium
Identify the bug: `if (x = 0 OR 1 OR 2)` is meant to test whether x is 0, 1, or 2.

Common mistakes

  • Confusing AND with OR in complex conditions, reversing the intended logic
  • Forgetting operator precedence—NOT binds before AND, which binds before OR—leading to unexpected results without parentheses
  • Using natural language intuition that fails in code: 'x is 5 or 10' must be written as 'x == 5 OR x == 10', not 'x == 5 OR 10'

Why this formula matters

Most real rules have more than one part: 'age 13 or older and has parent permission', 'free shipping for members or orders over $50'. Logical operators let a program state such rules exactly. Choose the wrong one and the program still runs but quietly does the wrong thing: AND where you meant OR lets almost nobody through, and OR where you meant AND lets almost everyone in.

Frequently asked questions

What is the Logical Operators formula?

Operators that combine or modify boolean expressions: AND (true only when both operands are true), OR (true when at least one operand is true), and NOT (reverses a boolean value from true to false or vice versa).

How do you use the Logical Operators formula?

Use logical operators when one decision depends on two or more yes/no facts, or on the opposite of one. Listen for and, or, not, either, between: 'between 1 and 9' becomes x >= 1 AND x <= 9, and 'unless it rains' becomes NOT raining. A single comparison needs no operator. If you must list the result for every possible combination of inputs, build a truth table; if the question is which block of code runs, that is selection.

Why is the Logical Operators formula important in CS Thinking?

Most real rules have more than one part: 'age 13 or older and has parent permission', 'free shipping for members or orders over $50'. Logical operators let a program state such rules exactly. Choose the wrong one and the program still runs but quietly does the wrong thing: AND where you meant OR lets almost nobody through, and OR where you meant AND lets almost everyone in.

What do students get wrong about Logical Operators?

AND requires ALL conditions true; OR only requires ONE — easy to confuse.

What should I learn before the Logical Operators formula?

Before studying the Logical Operators formula, you should understand: boolean logic, selection.