for (numeric) |
---|
The numeric for lets you loop a specific number of times, eg.
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:
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: The three control expressions (start, finish, step) are evaluated once and stored into local variables (start variable, finish variable, step variable). These evaluations must result in numbers or an error is raised. If omitted, the step variable is assumed to be one. The loop control variable (var) is set to the start variable. If the step variable is positive, then the loop control variable is tested to see if it is less than, or equal to, the finish variable. If not, the loop exits. If the step variable is negative or zero, then the loop control variable is tested to see if it is greater than, or equal to, the finish variable. If not, the loop exits. The loop body is now executed. The step variable is added to the loop control variable. Control passes back to the start of the loop to test the loop control variable again. See Also ... Lua keywords/topics
assignment
Topics
Lua base functions
(Help topic: lua=for (numeric)) |
Enter a search string to find matching documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.