XFA Specification
Chapter 23, FormCalc Specification
Grammar and Syntax
823
A for loop terminates when the start expression has surpassed the end expression. This can be both in an
upwards direction, if you use
upto
, or in a downward direction, if you use
downto
.
Examples
The following example calculates of the mathematical value of a number raised to the power of another
number.
var y = 1
for var x = 1 upto power do
y = y * base
endfor
total=y
where
power
,
base
, and
total
are fields in the same subform as the script.
The following example uses the step feature to calculate the sum of all even numbers between 1 and 100.
var x var evensum=0
for x=2 upto 100 step 2 do evensum=evensum+x endfor
For Each Expressions
96 ForeachExpression ::=
'foreach' Identifier 'in' '(' ArgumentList ')'
'do' ExpressionList 'endfor'
A For Each expression iterates over the expression list for each value in its argument list.
The
in
condition, which is executed only once (after the loop variable has been declared) controls the
iteration of loop. Before each iteration, the loop variable is assigned successive values from the argument
list. The argument list cannot be empty.
Note:
Use a comma (,) to separate more than one simple expression in the argurment list.
Return
The value of the last expression list that was evaluated, or zero(0), if the loop was never entered.
Example
The following example calculates travelling expenses:
var total = 0.0
foreach expense in ( travel_exp[*], living_exp[*],parking_exp[*] ) do
total = total + expense
endfor
While Expression
97 WhileExpression ::=
'while' '(' SimpleExpression ')' 'do' ExpressionList 'endwhile'
A While Expression is an iterative statement or loop that evaluates a given simple expression. If the result
of the evaluation is true (1), FormCalc repeatedly examines the
do
condition and returns the results of the
expression lists. If the result is false (0), then control passes to the next statement.
Home Index Bookmark Pages
Pages: Home Index All Pages