18th Chapter logical Operators

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.