A detailed explanation of how to use if statements in Lua _lua

Source: Internet
Author: User
Tags lua

An If statement consists of one or more statements consisting of a Boolean expression.
Grammar

The IF statement syntax for the LUA programming language is:

Copy Code code as follows:
if (boolean_expression)
Then
--[statement (s) would execute if the Boolean expression is true--]
End

If the Boolean expression evaluates to the code if the IF statement is true, the block is executed. If the end of the IF statement (after the closing brace) evaluates to False, the first set of code is executed.

The LUA programming language assumes a value of false if any combination of Boolean true and non-0 values is true and whether it is Boolean false or 0. It should be noted, however, that the LUA 0 values are also considered true.

Example:

Copy Code code as follows:
--[local variable definition--]
A = 10;

--[Check the Boolean condition using if statement--]
if (a < 20)
Then
--[if condition is true then print the following--]
Print ("A is less than 20");
End
Print ("Value of A is:", a);

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

Copy Code code as follows:
A is less than 20
Value of a is:10


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.