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