Lua中的for循环

print("\n======session 1======\n")

for i = 1, 5 do
    print(i)
end

print("\n======session 2======\n")

for i = 1, 10, 2 do
    print(i)
end

print("\n======session 3======\n")

for i = 10, 1, -1 do
    print(i)
end

print("\n======session 4======\n")

for i = 1, math.huge do
    if (0.3*i^3 - 20*i^2 - 500) >= 0 then
        print(i)
        break
    end
end

print("\n======session 4======\n")

local a = {"a","b","c","d"}

for i, v in ipairs(a) do
    print("index", i, "value", v)
end

print("\n======session 5======\n")

local days = {
    "Monday", "Tuesday", "Wednesday", "Thursday",
    "Friday", "Saturday","Sunday"
 }

for i, v in ipairs(days) do
    print("index", i, "value", v)
end

local Days = {}

for i, v in ipairs(days) do
    Days[v] = i
end

for i, v in ipairs(days) do
    print("index", v, "value", Days[v])
end

print("\n======session 6======\n")