Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- SLAX Variables Overview
- XPath Overview
- ACX, EX, J, M, MX, SRX, T Series
- mvar
while
Syntax
while (expression) {
/* body */
}
Release Information
Statement introduced in version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.
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 is not changed. In the expression, you should use a mutable variable, which is declared using the mvar statement, to avoid creating an infinite loop.
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 true. |
SLAX Example
In the example, the while loop parses through the item list until the desired value is found. When that value is detected, $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; }
Usage Examples
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- SLAX Variables Overview
- XPath Overview
- ACX, EX, J, M, MX, SRX, T Series
- mvar
Published: 2013-03-05
Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- SLAX Variables Overview
- XPath Overview
- ACX, EX, J, M, MX, SRX, T Series
- mvar