Statements (GNU Radius Reference Manual)

Next: , Previous: , Up: Full Syntax Description [Contents][Index]


10.2.8.8 Rewrite Statements

The Rewrite statements are: expressions, conditionals, loops, and return statements. A simple statement is terminated by a semicolon. A compound statement is one or more statements enclosed in curly brackets.

Conditionals

A conditional statement is:

if (expr)
 a
else
 b

Here, expr is any expression, a and b are statements (simple or compound). The expression expr is evaluated and its result is coerced to boolean value. If the resulting value is ‘true’, then the statement a is executed, otherwise, the statement b is executed. The else part is optional. Conditional expressions can be chained:

if (e1)
 a;
else if (e2)
 b;
else if (e3)
 c;
else
 d;

This is equivalent to

if (e1)
 a;
else {
 if (e2)
 b;
 else {
 if (e3)
 c;
 else
 d;
 }
}

Loops

Two kinds of loops are provided: while, and do-while loops.

A while loop is:

while (expr) stmt

A do-while loop is:

do stmt while (expr)

Both loops run stmt (which is usually a compound statement) for as long as expr evaluates to ‘true’. The main difference is that a while loop is executed 0 or more times, while a do-while loop is executed 1 or more times.

The following statements can appear within a stmt in a loop:

break

Break from the loop immediately. Control flow resumes at the first statement after the loop.

continue

Branch to expr immediately.

The return statement

return expr

The return statement stops execution of the current function and returns to the caller. Its argument is evaluated and the resulting value becomes the function return value.


Next: Function calls, Previous: Rewrite Declarations, Up: Full Syntax Description [Contents][Index]

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