1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #hello world >print("Hello World!") #注释 >
#字符串连接 > print("a" .. 'b') #字符串长度 > print(#"www.runoob.com") #表
a = {} a["key"] = "value" key = 10 a[key] = 22 a[key] = a[key] + 11 for k, v in pairs(a) do print(k .. " : " .. v) end #函数
function factorial1(n) if n == 0 then return 1 else return n * factorial1(n - 1) end end print(factorial1(5)) factorial2 = factorial1 print(factorial2(5)) #while循环 while( true ) do print("循环将永远执行下去") end #if循环
if(0) then print("0 为 true") end
if( 布尔表达式 1) then
elseif( 布尔表达式 2) then
elseif( 布尔表达式 3) then else end #for循环 days = {"Suanday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"} for i,v in ipairs(days) do print(v) end
for i=10,1,-1 do print(i) end
|