for loop in lua code example
Example 1: lua for loop
-- For K,V in table
for k,v in pairs(tbl) do
print(k)
print(v)
end
-- For i=0, num
for i=0, num do
print(i)
end
Example 2: lua how to make a loop
for init,max/min value, increment
do
statement(s)
end
Example 3: For loop lua
for startValue, EndValue, [increments] do
--code to execute
end
--The increments value is optional. If it isn't defined, it is assumed to be "1"
Example 4: for loop lua
local t = {}
for index, value in ipairs(t) do
print(index, value)
end
Example 5: for loop lua
local t = {}
for key, value in pairs(t) do
print(key, value)
end
Example 6: loop in lua
-- a loop will repeat the code for a limited amount of time
-- let make one
for a = 1 --(from where you want it to start),10 --(how long you want it to be),1 --[How many jumps it needs to make(ex 2, 4, 6, 8,10)]
print(a) -- now it will count to 10
end