Skip to content

Instantly share code, notes, and snippets.

View kaworun's full-sized avatar

Kenta Oki kaworun

View GitHub Profile
age = 17
if age > 18 then
print("Z")
elseif age >= 17 then
print("D")
elseif age >= 15 then
print("C")
elseif age >= 12 then
print("B")
x = 10 + 5
y = 5 * 5
z = 10 % 3
n = 2 ^ 3
print(x)
print(y)
print(z)
print(n)
n = {123, 789, "xyz"}
print(n[3])
print(#n)
me = {name = "hoge", age = 17}
print(me["name"])
print(me.age)
x, y, z = 0, 0, 0
-- while
while x <=10 do
x = x + 1
print(x)
end
-- break
while y <= 10 do
a = {10, 15, 20, 30}
b = {"ok", "ng"}
if a[3] > 17 then
print(b[1])
else
print(b[2])
end
-- for
for i = 0, 9 do
print(i)
end
-- for table
a = {10, 20, "hoge"}
b = {name = "huga", age = 17}
for i, value in ipairs(a) do
name = {"kaworun", "yozora"}
text1 = "さんの得点は…"
text2 = "さんの平均点は…"
ja = {49, 57}
en = {60, 45}
ss = {63, 90}
db = {95, 99}
sum = ja[1] + en[1] + ss[1] + db[1]
x = math.max(200, 173, 37)
print(x)
x = math.min(2, 83, 927)
print(x)
x = math.ceil(273.7)
print(x)
x = math.floor(21.3)
-- s = string.len("渚カヲル")
s = #("渚カヲル")
print(s)
s = string.sub("渚カヲル", 2, 3)
print(s)
s = string.find("渚カヲル", "渚")
print(s)
x = 100
y = 12.3456789
name = "hogehoge"
s = string.format("x: %-10d, y: %.4f, name: %s", x, y, name)
print(s)
--[[
left %-10~
right %10~