while
Syntax
while (expression) {
/* body */
}/* Syntax with optional parentheses added in SLAX version 1.3 */
while expression {
/* body */
}Description
Repeatedly execute a block of statements until the specified condition evaluates to
false.
The condition is an XPath expression that is converted to a Boolean type. If the
expression evaluates to true, the contents of the while loop are
executed. The loop continues to execute until the expression evaluates to
false. During execution, the context does not change. In the
expression, you should use a mutable variable to avoid creating an infinite loop.
You declare mutable variables using the mvar statement.
Attributes
expression |
XPath expression, which is cast to boolean type and used as the condition
for the while loop. The code block contents are executed as long as the
condition evaluates to Starting in SLAX version 1.3, the parentheses enclosing the statement expression are optional. |
SLAX Example
In the example, the while loop parses through the item list until the required value is found.
When the loop detects that value, $seen is set to true, and the
while loop exits.
mvar $seen = false();
mvar $count = 1;
while (not($seen)) {
if (item[$count]/value) {
set $seen = true();
}
set $count = $count + 1;
}Release Information
Statement introduced in SLAX version 1.1.
Support for syntax with optional parentheses added in SLAX version 1.3.