Skip to content

Commit 86785a0

Browse files
zhangjiongwxegonSchiele
authored andcommitted
Add Lua code for chapter 5
1 parent 5f2626c commit 86785a0

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local book = {}
2+
-- an apple costs 67 cents
3+
book["apple"] = 0.67
4+
-- milk costs $1.49
5+
book["milk"] = 1.49
6+
book["avocado"] = 1.49
7+
8+
for key, value in pairs(book) do
9+
print(key .. ": " .. value)
10+
end

05_hash_tables/lua/02_check_voter.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
local voted = {}
2+
function check_voter(name)
3+
if voted[name] then
4+
print("kick them out!")
5+
else
6+
voted[name] = true
7+
print("let them vote!")
8+
end
9+
end
10+
11+
check_voter("tom")
12+
check_voter("mike")
13+
check_voter("mike")

0 commit comments

Comments
 (0)