Looking for swift Answers? Try Ask4KnowledgeBase
Looking for swift Keywords? Try Ask4Keywords

Swift Language Boolean Logical Operators


Example

The OR (||) operator returns true if one of its two operands evaluates to true, otherwise it returns false. For example, the following code evaluates to true because at least one of the expressions either side of the OR operator is true:

if (10 < 20) || (20 < 10) {
    print("Expression is true")
}

The AND (&&) operator returns true only if both operands evaluate to be true. The following example will return false because only one of the two operand expressions evaluates to true:

if (10 < 20) && (20 < 10) {
    print("Expression is true")
}

The XOR (^) operator returns true if one and only one of the two operands evaluates to true. For example, the following code will return true since only one operator evaluates to be true:

if (10 < 20) ^ (20 < 10) {
    print("Expression is true")
}