-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.lua
74 lines (63 loc) · 1.6 KB
/
hello.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function sayName()
local name = 'Hello World'
print(name)
end
function sayInfo(name, age, nationality)
nationality = 'Thai'
age = '21'
name = name or 'Prin' --more ways to describe varaibles
io.write(name ,"\n" ,age ,"\n" ,nationality)
end
function forloop()
local dict = {
['moon'] = "🌕",
['cheese'] = "🧀"
}
for k,v in pairs(dict) do
print(k,v)
end
end
function whileloop()
local i = 0
local count = 0
while i <= 10 do
count = i + 1
i = i + 1
end
print('count is ' .. count)
end
function conditionalIf()
-- ~= is != in lua
local age = 20
if age < 18 then
print('not over 18') -- if age is less than 18 it will print this
elseif age == 18 then
print('you are 18') -- if age equals to 18 it will print this
else
print('you are older than 18') -- if age is older than 18 it will print this
end
end
function combinationStatement()
local x = 101
if x == 10 and x > 0 then -- 'and' is &&
print('dog') -- if x is more than 0 and equals to 10 it will print this
elseif x == 100 or x < 120 then -- 'or' is ||
print('cat') -- if x equals to 100 but less than 120 will print this
else
print('bird') -- if the condition doesn't match any above it will print this
end
end
function nestedStatement()
local x = 10
local isAlive = true
if x == 10 then
if isAlive == true then
print('dog')
else
print('cat')
end
end
end
-- whileloop()
print('Hello World')
print('Test github upload')