Boolean Expressions

18. Boolean Expressions with OR


    cash >= 25000 true credit >= 25000 false cash >= 25000 || credit >= 25000 true

Boolean Expressions with OR


The OR operator is used in a boolean expression to check that there is at least one true. If both sides are true, the entire expression is true. If just one side is true, the entire expression is true. If both sides are false, the entire expression is false. The OR operator is a logical operator because it combines two true/false values into a single true/false value.

Here is how || works:

      • true  || true  = true
      • false || true  = true
      • true  || false = true
      • false || false = false

OR checks that at least one requirement is met. This type of OR is called an inclusive OR because its value is true for one or two true values.

Often in English word "or" is used when any number of conditions can be true. For example, in this sentence

Successful job seekers must have experience or training.

Sometimes the English word "or" is used when only one condition can be true at a time. For example, in this sentence

It will rain today or it will be clear.

only one condition, "rain" or "clear", can be true. This is called an exclusive OR. In programming, "or" means inclusive or.

Question 18:

Here is a boolean expression:

    34 > 2 || 5 == 7
Is this expression true or false ?