lua for loop Code Answer’s
The for loop is a statement in Lua, which allows you to repeat a block of code while a condition is true. The syntax is: for var in array do block endThe result of this statement will be the value of var at each iteration of the loop. Each time through the loop, var will be set to the value of whatever element is returned by the block.
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
lua while loops
--// Basic while true do loop
while true do
--// Looped text
print("Looped Text")
--// Time the loop waits before looping again
wait(1)
end
lua how to make a loop
for init,max/min value, increment
do
statement(s)
end
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"
Source: www.lua.org
for loop lua
local t = {}
for index, value in ipairs(t) do
print(index, value)
end
The first argument of the for keyword is an expression that evaluates to an integer or string. The second argument is an expression that evaluates to a table, and the third argument is a block of code (also known as an expression). In this example, we have three different variables (array, var and do_block) that are all assigned values inside the do_block block. When run at different times, these values will be evaluated each time through the loop body.