Example
Copyright © 2010, Juniper Networks, Inc.
shade := env.getline("Do you prefer dark " $ color $
" or light " $ color $ "? ") #>
<# if shade = "dark" #>
! I like dark colors, too.
<# elseif shade = "light" #>
! I prefer dark colors myself.
<# else #>
! Hmmm, that's neither dark nor light.
<# endif #>
<# else #>
! Oh.
That's nice.
<# endif #>
<# else #>
! I didn't think so!
<# endif #>
<# endtmpl #>
While Constructs
While constructs provide a means to repeatedly execute one or more portions of the
macro based on a condition that changes during the execution. A while construct consists
of the following components:
An opening while expression
A group of any number of additional expressions
An endwhile expression to indicate the end of the while structure
The while expression must include a lone environment value command, a local variable,
a literal, or some operation using one or more operators. Each time that this expression
evaluates to nonzero, the associated expression group is executed.
You can place an iteration expression after the while expression. This optional expression
is evaluated after each execution of the while expression group.
You can include if structures within a while structure. You can also include special control
expressions indicated by the break or continue expressions. The break expression breaks
out of the while structure by halting execution of the expression group and executing the
first expression after the endwhile statement. The continue expression skips over the rest
of the expression group, evaluates any iteration expression, then continues with the
execution of the while structure. The while structure is limited to 100,000 repetitions by
default. You can nest up to 10 while structures.
The following sample macro demonstrates various while structures:
<#
while_examples
<# //---------------------------------------- #>
<# // Remember that variables are automatically initialized to 0. #>
! Table of squares of the first 10 integers:
<# while ++i <= 10 #>
!<#i;"
";i*i;"\n"#>
<# endwhile #>
<# // Remember that the value of a string used as an integer is the number. #>
<# // of characters in the string.
<# stars := "*" #>
<# while stars < 10, stars := stars $ "*"#>
!<# stars;"\n" #>
Chapter 8: Writing CLI Macros
#>
#>
473
Need help?
Do you have a question about the JUNOSE SOFTWARE FOR E SERIES 11.3.X - SYSTEM BASICS CONFIGURATION GUIDE 2010-10-04 and is the answer not in the manual?
Questions and answers