choosing a logical operator
on this page
how to choose an operator
this guide helps you select the right logical operator based on the outcome you want to achieve. instead of asking βwhat does AND do?β, this page answers the question, βwhich operator should i use if i needβ¦?β
use the summary table below to find the operator that fits your needs.
outcome to operator cheat sheet
use this table as a quick reference to find the operator that matches your goal.
if you need the result to be true when⦠| use this operator | example use case |
---|---|---|
all of your conditions are true | conjunction (and) | user.is_logged_in and user.has_permission |
at least one of your conditions is true | disjunction (or) | is_admin or is_editor |
your two conditions have the same value (both T or F) | biconditional (iff) | feature_enabled == user_setting_is_true |
a true premise leads to a true conclusion | implication (ifβ¦then) | if is_raining then ground_is_wet |
you need to invert a single conditionβs value | negation (not) | not user.is_banned |
detailed scenarios
goal: all conditions must be met
- scenario: you are granting access to a secure resource. the user must be logged in, have the correct permissions, and be on a trusted network.
- operator: conjunction (and)
- logic:
is_logged_in AND has_permission AND is_trusted_network
- outcome: the expression is only
True
if all three individual conditions areTrue
.
goal: any one of several conditions is enough
- scenario: you are checking if a user is eligible for a discount. they qualify if they are a student, a senior, or a veteran.
- operator: disjunction (or)
- logic:
is_student OR is_senior OR is_veteran
- outcome: the expression is
True
if the user fits into any one of those categories.
goal: a condition must be false
- scenario: you want to show a login button, but only to users who are not currently authenticated.
- operator: negation (not)
- logic:
NOT is_authenticated
- outcome: the expression is
True
only whenis_authenticated
isFalse
.
goal: two states must be identical
- scenario: you are verifying data integrity. a record is considered valid only if its
is_processed
flag has the same value as itsis_archived
flag. - operator: biconditional (iff)
- logic:
is_processed IFF is_archived
- outcome: the expression is
True
if both flags areTrue
or if both flags areFalse
.
goal: a specific condition guarantees an outcome
- scenario: you have a system rule: if a user has more than 100 points, they must be a βgoldβ member.
- operator: implication (ifβ¦then)
- logic:
has_100_points IMPLIES is_gold_member
- outcome: this rule is only violated (evaluates to
False
) if a user has 100+ points but is not a gold member. if they have fewer than 100 points, the rule holds true regardless of their status.
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ