@For (Formula Language)
Executes one or more statements iteratively while a condition remains true. Executes an initialization statement. Checks the condition before executing the statements and executes an increment statement after executing the statements.
Syntax
@For( initialize ; condition ; increment ; statement ; ... )
Parameters
initialize
A statement that assigns an initial value to a variable in condition.
condition
Expression that returns a value of True (1) or False (0).
increment
A statement that changes the initialized variable, typically incrementing it.
statement
A formula language statement. The maximum number of statements you can include is 252.
Return value
true
True (1) unless an error occurs during execution of the condition. An "unexpected data type" error occurs if the conditional expression results in a non-numeric value.
Usage
@For executes the initialize statement once. Next @For evaluates the condition. If the condition is True (1), @For executes the statements, executes the increment statement, and evaluates the condition again. If the condition is False (0), @For terminates.
The formula engine exits a formula or breaks an infinite loop if the time spent performing the iterations exceeds the standard timeout value allowed for an operation.
Examples
- This agent displays the elements of the Categories field one at
a time.
@For(n := 1; n <= @Elements(Categories); n := n + 1; @Prompt([OK]; "Category " + @Text(n); Categories[n]))
- This computed field formula concatenates the list elements in
the fname and lname fields:
@For(n :=1; n<=@Elements(fname); n:= n + 1; full := @If(n=1;fname[n] + " " + lname[n];full : (fname[n] + " " + lname[n]))); full
If fname contains: "Catherine":"Patricia":"Maureen" and lname contains: "Rolling":"Kearns":"Legacy", the result is: "Catherine Rolling;Patricia Kearns;Maureen Legacy." If fname and lname each contain a different number of elements, be sure to include the field that has fewer elements in the @Elements function or an "Array index out of bounds" error results.
- This computed field formula displays the longest name in a text
list of poets names stored in the poets field. If the poets field
contains "T.S. Eliot":"Dorothy Parker":"Edna St. Vincent Millay":"e.e.
cummings": this field displays Edna St. Vincent Millay.
temp := ""; @For(n := 1; n <= @Elements(poets); n := n + 1; @If(@Length(poets[n])>@Length(temp); temp := poets[n];temp)); temp