Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

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

s_loopVar

Name of the local loop variable that must not be changed inside the loop

x_initialValue

Integer expression setting the initial value for the local loop variable

x_finalValue

Integer expression giving final limit value for the loop

g_expr1

Expression to evaluate inside loop

g_expr2

Additional expression(s) to evaluate inside loop

Value Returned

t

This construct always returns t

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

Flow Control Functions


Return to top
 ⠀
X