a=10
name='al' .. 'ex''
也可以同时对多个变量进行赋值,以变量的个数为基础,没有匹配的变量将会赋值为nil。如果赋值语句个数多余变量个 数,则会忽略多余的赋值语句
a , b = 10,20
a,b=10,20,30
a,b,c=10,20 ->a=10,b=20,c=nil
a,b=fun() -> 函数返回再个值,分别赋值给a,b
变量与作用域
使用local来声明chunk或是局部变更
x = 10
print('x='..x)
if x > 0 then
local x=0
print('in block='..x)
end
print(aa)
do
local aa = 'alex'
print('in do end block:'..aa)
end
print(aa)
条件控制语句
if语句块
if conditions then
then-part
end;
if conditions then
then-part
else
else-part
end;
if conditions then
then-part
elseif conditions then
elseif-part
.. --->多个elseif
else
else-part
end;
while语句块
while condition do
statements;
end;
repeat语句块:
repeat
statements;
until conditions;
for 语句块
for y=1,10,2 do
print(y)
end