Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
Automation Scripting User Guide
Table of Contents Expand all
list Table of Contents
file_download PDF
{ "lLangCode": "en", "lName": "English", "lCountryCode": "us", "transcode": "en_US" }
English
keyboard_arrow_right

while

date_range 13-Jan-21

Syntax

content_copy zoom_out_map
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 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.

content_copy zoom_out_map
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 version 1.1 of the SLAX language, which is supported in Junos OS Release 12.2 and later releases.

footer-navigation