The logical operators are operands with two Boolean values or expressions that return a Boolean value. You use these operators to handle expressions that consist of either true or false parts. A logical operator is used to test that two expressions are true or one of them is true. The following table lists and describes the logical expressions supported by Swift language
For example, suppose you already have two variables, x and Y, and the values are true and false, respectively. To test whether X and Y are both true, use the logical AND operator, as shown below
Let X = True
Let y = False
Let a = x && y
In the above example, the value of a is false, because X and Y are not both true
If you have a true interest in the operand, you can use the logical OR operator as follows:
Let X = True
Let y = False
Let B = x | | Y
In the above example, the value of B is true because the value of one of the operands (x) is True
Use logical non (!) operator to get the opposite side of a Boolean value. A Boolean value preceded by an exclamation point indicates the opposite side of the Boolean. So,!true means true,!false is True
If you want a Boolean value on the opposite side of X, you can use the following code:
Let X = True
Let y = False
Let C =!x
The value of C is false because the value of X is True
Note: We can assign the value of the logical operator operation to a Boolean constant or variable, and you will often use the logical operator in the IF statement
18th Chapter logical Operators