Usage of logical operators in Lua

Source: Internet
Author: User

Usage of logical operators in Lua

This article describes how to use logical operators in Lua. It is the basic knowledge of Lua beginners. For more information, see

The following table lists all logical operators supported by Lua. Assume that variable A holds true, and variable B holds false:

Example

Try the following example to understand the logical operators provided by all Lua programming languages:

The Code is as follows:

A = 5

B = 20

If (a and B)

Then

Print ("Line 1-Condition is true ")

End

If (a or B)

Then

Print ("Line 2-Condition is true ")

End

-- Lets change the value ofa and B

A = 0

B = 10

If (a and B)

Then

Print ("Line 3-Condition is true ")

Else

Print ("Line 3-Condition is not true ")

End

If (not (a and B ))

Then

Print ("Line 4-Condition is true ")

Else

Print ("Line 3-Condition is not true ")

End

When the above program is established and executed, it will produce the following results:

The Code is as follows:

Line 1-Condition is true

Line 2-Condition is true

Line 3-Condition is true

Line 3-Condition is not true

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.