-Lua中没有++或者--的骚操作
-while loop
sum = 0 num = 1 while num <= 100 do sum = sum + num num = num + 1 end print("sum =",sum)
-if else
if age == 40 and sex =="Male" then print("男人四十一枝花") elseif age > 60 and sex ~="Female" then print("old man without country!") elseif age < 20 then io.write("too young, too naive!\n") else local age = io.read() print("Your age is "..age) end
~=表示!=
io.read()也就是stdin
io.write()也就是stdout
字符串拼接的+也就是..
与也就是and
或也就是or
非也就是not
-for loop
从1加到100 sum = 0 for i = 1, 100 do sum = sum + i end 从1到100的奇数和 sum = 0 for i = 1, 100, 2 do sum = sum + i end 从100到1的偶数和 sum = 0 for i = 100, 1, -2 do sum = sum + i end
-until loop
sum = 2 repeat sum = sum ^ 2 --幂操作 print(sum) until sum >1000
原文地址:https://www.cnblogs.com/otakuhan/p/8605873.html
时间: 2024-10-09 05:37:35