@While (Formula Language)

Executes one or more statements iteratively while a condition is true. Checks the condition before executing the statements.

Note: This @function is new with Release 6.

Syntax

@While( condition ; statement ; ... )

Parameters

condition

Expression that returns a value of True (1) or False (0).

statement

A formula language statement. The maximum number of statements you can include is 254.

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

@While evaluates the condition. If the condition is True (1), @While executes the statements then evaluates the condition again. If the condition is False (0), @While terminates. Typically one of the statements should change a value in the conditional expression so that the loop stops at some point.

Tip: If you are looping through a field containing a list, be sure the Allow multiple values check box is selected in the Field Properties box for the list field.

For other iterative statements, see @DoWhile and @For.

Examples

This agent displays the elements of the Categories field one at a time.
n := 1;
@While(n <= @Elements(Categories);
@Prompt([OK]; "Category " + @Text(n); Categories[n]);
n := n + 1)