lua for loop
-- Define the start value for the loop variable
for i = 1, 5 do
-- Loop body: code to be executed in each iteration
print("Iteration " .. i)
end
Initialization:
i
is initialized with the value 1.Condition Check: Check if the value of
i
is less than or equal to 5.Execute Loop Body: If the condition is true, execute the code inside the loop body.
Update Variable: Increment
i
by 1 after executing the loop body.Repeat: Go back to step 2 and repeat the process until the condition is false.
Termination: Exit the loop when the condition is false.