Basic Lua learning syntax

Source: Internet
Author: User
Assignment Statement

Lua can assign values to multiple variables at the same time. The variable list is separated by commas. Variables on the right side of the value assignment statement are sequentially assigned to the left.
A, B = 10, 2 * x <---> A = 10; B = 2 * X;
Lua calculates all values on the right and then performs the value assignment operation.
X, Y = Y, X -- Swap X for y

When the number of variables and the number of values are different when both values are assigned,
A. number of variables> A cloth nil with insufficient values
B. The number of variables <The number of excess values is ignored.

A, B, c = 0, 1
Print (A, B, C);-> 0, 1, Nil

Control Structure statement
Conditional expression: Lua considers flase and nil as false, and others as true.
If... then... End; if... then... Else... end; if... then... Else if... Then... end;

While statement
While condition do
Statements;
End;

For statement:
1. Numeric for loop: for Val = beg, end, step do
...
End
Note: Beg, end, and step are expressions and will only be calculated once. Step can be omitted. The default value is 1.
Val is a local variable. Valid only in the loop

2. Fan type for Loop
Construct reverse tables
Days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday "}

Revdays = {}
For I, V in ipairs (days) Do
Revdays [v] = I
End

Break and return statements.
Lua syntax requires that break and return can only appear at the end of the block.

Basic Lua learning syntax

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.