In the Lua programming language, we can use various control statements. This includes the numeric
The syntax is as follows.
for Name ‘=’ initial_value ‘,’ limit [‘,’ step] do -- code end
initial_value is used to specify the value on which our counter will be initialized.
limit is used to specify the final number of our iteration.
step (not mandatory) is used to specify the number that will be added to our counter each iteration. By default, it is
In this example, we will see how to enumerate numbers from to .
for i = 0, 10, 1 -- '1' is not required here do print(i) end
0 1 2 3 4 5 6 7 8 9 10
for statement in line causes line to be executed repeatedly until the value of
i becomes equal to .
Consequently, all the values of
i in the range to are printed.
View all Courses