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.
Example
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" #>
473
Copyright © 2010, Juniper Networks, Inc.
Chapter 8: Writing CLI Macros
Summary of Contents for JUNOSE 11.3
Page 6: ...Copyright 2010 Juniper Networks Inc vi...
Page 8: ...Copyright 2010 Juniper Networks Inc viii JunosE 11 3 x System Basics Configuration Guide...
Page 24: ...Copyright 2010 Juniper Networks Inc xxiv JunosE 11 3 x System Basics Configuration Guide...
Page 32: ...Copyright 2010 Juniper Networks Inc 2 JunosE 11 3 x System Basics Configuration Guide...
Page 146: ...Copyright 2010 Juniper Networks Inc 116 JunosE 11 3 x System Basics Configuration Guide...
Page 166: ...Copyright 2010 Juniper Networks Inc 136 JunosE 11 3 x System Basics Configuration Guide...
Page 432: ...Copyright 2010 Juniper Networks Inc 402 JunosE 11 3 x System Basics Configuration Guide...
Page 488: ...Copyright 2010 Juniper Networks Inc 458 JunosE 11 3 x System Basics Configuration Guide...
Page 524: ...Copyright 2010 Juniper Networks Inc 494 JunosE 11 3 x System Basics Configuration Guide...
Page 554: ...Copyright 2010 Juniper Networks Inc 524 JunosE 11 3 x System Basics Configuration Guide...
Page 566: ...Copyright 2010 Juniper Networks Inc 536 JunosE 11 3 x System Basics Configuration Guide...
Page 588: ...Copyright 2010 Juniper Networks Inc 558 JunosE 11 3 x System Basics Configuration Guide...
Page 613: ...PART 3 Index Index on page 585 583 Copyright 2010 Juniper Networks Inc...
Page 614: ...Copyright 2010 Juniper Networks Inc 584 JunosE 11 3 x System Basics Configuration Guide...
Page 632: ...Copyright 2010 Juniper Networks Inc 602 JunosE 11 3 x System Basics Configuration Guide...