## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

No credit card required

Chapter    18

Logical Operators

The logical operators are used with boolean values and expressions that return boolean values. You use these operators to deal with expressions that are made up of parts that can be either true or false. Logical operators are used to test whether two expressions are true or whether one expression is true. Table 18-1 describes the logical operators supported by Swift.

Logical Operators

Operator

Description

!x

Logical NOT

x && y

Logical AND

x || y

Logical OR

For instance, let’s assume you already have two variables, x and y, with values of true and false. To test and see whether both x and y are true, you would use logical AND, as shown in Listing 18-1.

Listing 18-1. Logical AND

`let x = truelet y = ...`

## With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

No credit card required