print("********如何實現switch-case********") local switch = { [1] = function() print ("case1") end, [2] = function() print ("case2") end, [3] = function() print ("case3") end } local a = 1 local f = switch[a] -- 如==nil 則是false if(f) then print(type(f)) f() else print("case defaule") end
--[[
-- 打印輸出以下
-- ********如何實現switch-case********
-- case1
--]]