Statements
时间:2008-01-17 来源:xiaoaizhen
Every statement is an expression, optionally followed by a modifier, and terminated by a semicolon. The semicolon may be omitted if the statement is the final one in a BLOCK.
Execution of expressions can depend on other expressions using one of the modifiers if, unless, while or until, for example:
-
EXPR1 if EXPR2 ;
EXPR1 until EXPR2 ;
The logical operators ||, && or ?: also allow conditional execution:
-
EXPR1 || EXPR2 ;
EXPR1 ? EXPR2 : EXPR3 ;
Statements can be combined to form a BLOCK when enclosed in {}. Blocks may be used to control flow:
-
if (EXPR) BLOCK [ [ elsif (EXPR) BLOCK ... ] else BLOCK ]
unless (EXPR) BLOCK [ else BLOCK ]
[ LABEL: ] while (EXPR) BLOCK [ continue BLOCK ]
[ LABEL: ] until (EXPR) BLOCK [ continue BLOCK ]
[ LABEL: ] for (EXPR; EXPR; EXPR) BLOCK
[ LABEL: ] foreach VAR† (LIST) BLOCK
[ LABEL: ] BLOCK [ continue BLOCK ]
Program flow can be controlled with:
Special forms are:
-
do BLOCK while EXPR ;
do BLOCK until EXPR ;
which are guaranteed to perform BLOCK once before testing EXPR, and
-
do BLOCK
which effectively turns BLOCK into an expression.
相关阅读 更多 +
排行榜 更多 +