fors
fors(s_loopVar x_initialValue x_finalValue g_expr1[g_expr2 ...] ) =>t
Description
Evaluates the sequence g_expr1, g_expr2 ... for each loop variable value, beginning with x_initialValue and ending with x_finalValue. In the SKILL++ mode, this function always locally wraps the loop or iterator local variable (s_loopVar) in a let() block while compiling the code. Local wrapping preserves the lexical scope of the loop variable. This function may work slower than its non-wrapped counterpart for. This is a syntax form.
First evaluates the initial and final values, which set the initial value and final limit for the local loop variable named s_loopVar. Both x_initialValue and x_finalValue must be integer expressions. During each iteration, the sequence of expressions g_expr1, g_expr2 ... is evaluated and the loop variable is then incremented by one. If the loop variable is still less than or equal to the final limit, another iteration is performed. The loop terminates when the loop variable reaches a value greater than the limit. The maximum value for the loop variable is INT_MAX-1.The loop variable must not be changed inside the loop. It is local to the for loop and would not retain any meaningful value upon exit from the for loop.
Arguments
|
Name of the local loop variable that must not be changed inside the loop |
|
|
Integer expression setting the initial value for the local loop variable |
|
Value Returned
Examples
(defun test_for (x)
fors( x x+1 x+9 println(x))
println(x)
)
test_for(9)
=> 10
11
12
13
14
15
16
17
18
9
nil
Also, see the example for the foreachs function.
Related Topics
Return to top