Add Lua code for chapter 5

This commit is contained in:
zhangjiong
2017-08-18 14:45:48 +08:00
committed by Aditya Bhargava
parent 5f2626c91b
commit 86785a0659
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
local book = {}
-- an apple costs 67 cents
book["apple"] = 0.67
-- milk costs $1.49
book["milk"] = 1.49
book["avocado"] = 1.49
for key, value in pairs(book) do
print(key .. ": " .. value)
end

View File

@@ -0,0 +1,13 @@
local voted = {}
function check_voter(name)
if voted[name] then
print("kick them out!")
else
voted[name] = true
print("let them vote!")
end
end
check_voter("tom")
check_voter("mike")
check_voter("mike")