Tutorial on using the IF statement nesting in Lua

Source: Internet
Author: User
Tags lua

This article mainly introduces the use of IF statements nested in Lua tutorial, is the basic knowledge in LUA learning, the need for friends can refer to the

Programming inline If-else Statements in Lua means that you can use an if or else if in another statement if or else if statement.

Grammar

The nested syntax for the IF statement is as follows:

The code is as follows:

if (Boolean_expression 1)

Then

--[executes when the Boolean expression 1 is true--]

if (Boolean_expression 2)

Then

--[executes when the Boolean expression 2 is true--]

End

End

You can nest else if...else in a way that resembles an if statement.

Example:

The code is as follows:

--[local variable definition--]

A = 100;

b = 200;

--[Check the Boolean condition--]

if (a = = 100)

Then

--[if condition is true then check the following--]

if (b = = 200)

Then

--[if condition is true then print the following--]

Print ("The Value of A is-B is 200");

End

End

Print ("Exact value of A is:", a);

Print ("Exact value of B is:", b);

When the above code is built and run, it produces the following results.

The code is as follows:

Value of A is and B are 200

Exact value of a is:100

Exact value of B is:200

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.