基本表达式
1: =, +, -, *, /, 赋值,加减剩除;
3: 字符串对象加法 ..; “Hello”..”world” --lua是用 .. 两个逗号来相加两个字符串
5: lua 没有 c/c++的缩写表达式 += -= *=, ++, --;
6: 逻辑运算:and 逻辑与, or 逻辑或
顺序执行
1: 一条一条语句的执行下去;
2: lua文件一开始就可以执行语句
条件语句
1: if then end: 如果条件成立,就执行if和end之间的代码块
2: if then else end 如果条件成立执行if,否则的话执行else
3: if then elseif then end 多个条件判断;
循环语句
1: for循环语句for exp1(开始), exp2(结束), exp3(步长) do
end
步长可以省略,默认为1;bi'ch
2: while循环语句
while 条件 then
end
local temp
temp =
3
-- 赋值
temp =
"hello world"
--temp变量爱存放字符对象的应用
temp = {
hello =
3,
}
print(temp)
print(temp.
hello)
--顺序执行
function
test_func()
print(
"test_func");
end
test_func()
--第一个启动脚本,
-- 字符串的加法用..
print(
"hello" ..
"world")
-- if 语句为true执行 ~= 不等于 == 等于
temp =
3
if temp >
4
then
print(
"do if")
end
---------------------------------------------------
if
true and
true
then
print(
"do if and")
end
--- and or
if
true
then
else
end
---------------------------------------------------------
if temp >
3
then
print(
"temp > 0")
elseif temp >
2
then
print(
"temp > 2")
end
-----------------------------------------------
--从1打印到10
local i =
1
for i =
1,
10
do
--默认步长为1
print(i)
end
-----------------------------------------------
--从1打印到10
for i =
1,
10,
2
do
print(i)
end
print(
"--------------------------------------")
--由大到小打印
for i =
10,
1, -
1
do
--步长为-1
print(i)
end
print(
"-----------------从1加到100---------------")
local sum =
0
for i=
1,
100,
1
do
sum = sum + i
end
print(sum)
-----------------------------------------------
--while 循环
i =
1
sum =
0
while i<=
100
do
sum = sum + i
i = i +
1
end
print(sum)
-- end