Loops (GNU Radius Reference Manual)

Next: , Previous: , Up: radtest [Contents][Index]


12.2.10 Loops

Two looping constructs are provided: while and do...while.

While loop

The syntax of a while loop is:

while cond
 stmt

Newline after cond is obligatory.

Do...while loop

do
 stmt
while cond

As usual do...while loop differs from its while counterpart in that its stmt is executed at least once.

The looping constructs can be nested to any depth.

Two special statements are provided for branching within loop constructs. These are break and continue.

Break statement stops the execution of the current loop statement and passes control to the statement immediately following it

while $x < 10
begin
 if $x < $y
 break
 …
 x = $x + 1
end
print "OK\n"

In the example above, execution of break statement passes control to print statement.

Break may also take an argument: a literal number representing the number of nested loop statements to break from. For example, the break statement in the sample code below will exit from the outermost while:

while $y < 10
begin
 while $x < 10
 begin
 if $x < $y
 break 2
 …
 x = $x + 1
 end
 …
 y = $y + 1
end
print "OK\n"

Continue statement passes control to the condition of the current looping construct. When used with a numeric argument, the latter specifies the number of the nesting looping construct to pass control to (as with break, the innermost loop is considered to have number 1, so continue is equivalent to continue 1).


Next: Built-in Primitives, Previous: Conditional Statements, Up: radtest [Contents][Index]

AltStyle によって変換されたページ (->オリジナル) /