Multiple Conditions

Multiple Conditions

Several conditions may be tested in an if statement using the following Boolean operators:

1.   AND
2.   OR
3.   NOT

These logical operators obey the rules outlined in the following truth tables:

AND

Example: Plants will only thrive if the weather is warm and wet.

Condition 1: Warm

Condition 2: Wet

Outcome: Thrive

False

False

False

False

True

False

True

False

False

True

True

True

The outcome is true only if both conditions are true.

OR

Example: Some plants will die if there is frost or drought.

Condition 1: Frost Condition 2: Drought Outcome: Die

False

False

False

False

True

True

True

False

True

True

True

True

The outcome is true if either condition is true otherwise it is false.

NOT
The Not operator only requires one operand and its function is to negate the operand.

Examples:
Not (True) – This will give the result False.
Not (False) – This will give the result True.

Rules
1. The AND operator compares two or more conditions and yields the value true if all of the conditions are true.
2. The OR operator compares two or more conditions and yields the value true if any of the conditions are true.
3. The NOT operator takes a single condition and yields a Boolean result which is the opposite of the result of the condition.

Next: Multiple Conditions Examples