--------------------------1.1-万能的Helloworld---------------------------------------------
--print("Hello World")
--------------------------1.2-定义函数---------------------------------------------
--[[
function fact(n)
if n==0 then
return 1
else
return n*fact(n-1)
end
end
print("enter a number:")
a = io.read("*number")
print(fact(a))
--]]
--这个例子定义了一个函数,计算输入参数n的阶乘;本例要求用户输入一个数字n,然后打印n的阶乘。
--------------------------1.3-调用另一文件----------------------------------------------
--调用另一文件
--[[
dofile("lib1.lua")
n = norm(3.4,1.0)
print(twice(n))
--]]
--------------------------1.4-全局变量----------------------------------------------
--[[
print(b)
b=10
print(b)
b=nil
print(b)
--]]
--------------------------1.5-词法约定---------------------------------------------
--[[
保留字:
and break do else elseif end false for function if in local nil not or repeat return then true until while
注释:
单行注释:--
--]]
--多行注释:--[[ --]]
--print("Hello World")
--------------------------1.2-定义函数---------------------------------------------
--[[
function fact(n)
if n==0 then
return 1
else
return n*fact(n-1)
end
end
print("enter a number:")
a = io.read("*number")
print(fact(a))
--]]
--这个例子定义了一个函数,计算输入参数n的阶乘;本例要求用户输入一个数字n,然后打印n的阶乘。
--------------------------1.3-调用另一文件----------------------------------------------
--调用另一文件
--[[
dofile("lib1.lua")
n = norm(3.4,1.0)
print(twice(n))
--]]
--------------------------1.4-全局变量----------------------------------------------
--[[
print(b)
b=10
print(b)
b=nil
print(b)
--]]
--------------------------1.5-词法约定---------------------------------------------
--[[
保留字:
and break do else elseif end false for function if in local nil not or repeat return then true until while
注释:
单行注释:--
--]]
--多行注释:--[[ --]]