Swift Language Booleans Boolean Logical Operators

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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")
}


Got any Swift Language Question?