For expressions

A for expression is a conditionally iterative statement or loop.

A for expression is particularly well-suited to looping situations in which unconditional repetition is needed. Conversely, situations in which conditional repetition is needed are often best dealt with using a while expression.

The value of the for expression is the value of the last evaluation list that was evaluated, or false (0).

The for condition initializes a FormCalc variable, which controls the looping action.

In the upto variant, the value of the loop variable will iterate from the start expression to the end expression in step expression increments. If you omit the step expression, the step increment defaults to 1.

In the downto variant, the value of the loop variable iterates from the start expression to the end expression in step expression decrements. If the step expression is omitted, the step decrements defaults to -1.

Iterations of the loop are controlled by the end expression value. Before each iteration, the end expression is evaluated and compared to the loop variable. If the result is true (1), the expression list is evaluated. After each evaluation, the step expression is evaluated and added to the loop variable.

Before each iteration, the end expression is evaluated and compared to the loop variable. In addition, after each evaluation of the do condition, the step expression is evaluated and added to the loop variable.

A for loop terminates when the start expression has surpassed the end expression. The start expression can surpass the end expression in either an upwards direction, if you use upto, or in a downward direction, if you use downto.

Expression

Syntax

Returns

For

for variable = start expression 
    (upto | downto ) end expression 
        (step step expression ) do 
    expression list 
endfor

The start, end, and step expressions must all be simple expressions.

The result of the list of expressions associated with the do condition.

In the following example, the values of the elements are added to a drop-down list from an XML file using the addItem method for all of the XML elements listed under list1:

    var List = ref(xfa.record.lists.list1) 
    for i=0 upto List.nodes.length - 1 step 2 do 
    $.addItem (List.nodes.item(i).value,"") 
    endfor

// Ethnio survey code removed