WHILE ... DO

WHILE (_expression) DO
Note

Note

This is a script command and operates only in scripts when scripting is enabled with the following command: enable cli scripting {permanent}.

Description

Executes a code block while the specified condition is true.

Syntax Description

expression Specifies the condition for which the statements should be executed while the condition is true.
statements Set of statements to be executed while the condition is true.

Default

N/A.

Usage Guidelines

This command is usually followed by statements to be executed while the condition is true and the entire construct is terminated by an ENDWHILE command.

The _expression must be enclosed in parentheses.

Nesting is supported up to five levels. An error message is displayed if there is incorrect nesting of WHILE conditions. An error message is displayed if a user tries to execute more than five WHILE conditions.

Ctrl-C can be used to break out of a WHILE loop(s). Breaking out of any number of WHILE loops always clears all the WHILE loops .

The operators mentioned in Using Operators can be used in an _expression in a WHILE condition.

You can insert comments by using a number sign (#).

Example

This example creates 10 VLANs, named x1 to x10:
set var x 1

WHILE ($x <= 10) DO
    create vlan v$x
    set var x ($x + 1)
ENDWHILE

History

This command was first available in ExtremeXOS 11.6.

Platform Availability

This command is available on ExtremeSwitching X435, X440-G2, X450-G2, X460-G2, X465, X590, X620, X690, and X695 series switches.