Swift - Operator OR Operator


The logical OR operator creates a logical expression a||b where either a or b needs to be true in order to evaluate to true.

The following table shows how the OR operator works on two values.

As long as either a or b is true, the expression evaluates to true.

a b a || b
true truetrue
truefalse true
false truetrue
false false false

Consider the following example:


var age = 0
if age > 13  || age < 1 {
    print("Age is out of range")


Here, the line "Age is out of range" will be printed if age is more than 13 or less than 1.

In this case, the line is printed, as age is 0.

Related Topic