for (numeric)

The numeric for lets you loop a specific number of times, eg.
for var = start, finish, step do
  some_action ()
end 
The three expressions are evaluated once before the loop starts. "start" is the initial value, "finish" is the limit of the loop, and "step" is what to add after each iteration. For example:
for i = 1, 10, 2 do
  print (i) --> 1, 3, 5, 7, 9
end 

for i = 10, 1, -3 do
  print (i) --> 10, 7, 4, 1
end 

for i = 1, 5 do
  print (i) --> 1, 2, 3, 4, 5
end 
The "loop control" variable (i in the examples above) is only visible inside the loop. It is a mistake to try to access it outside the loop. If you must remember what the loop control variable was when exiting a loop, save it in another variable.

You should not attempt to change the loop control variable. Doing so will lead to undefined results.

If you want to leave the loop from inside you can use a break statement.


More specifically what happens in the numeric "for" is:

Lua keyword/topics

Topics