?? 1076_8.html
字號:
sequence_of_statements ]
<b>end if</b> [ <i>if</i>_label ] ;
</pre>
<p>If a label appears at the end of an if statement, it must repeat the if label.
<p>For the execution of an if statement, the condition specified after <b>if</b>,and any conditions specified after <b>elsif</b>, are evaluated in succession(treating a final <b>else</b> as <b>elsif</b> TRUE <b>then</b>) until one evaluates to TRUE or all conditions are evaluated and yield FALSE. If one condition evaluates to TRUE, then the corresponding sequence of statements is executed; otherwise, none of the sequences of statements is executed.
<h2><a name="8.8"> <a href = "1076_8.HTM#8.8"> 8.8 </a> Case statement</a></h2>
<p>A case statement selects for execution one of a number of alternative sequences of statements; the chosen alternative is defined by the value of an expression.
<pre> case_statement ::=
[ <i>case</i>_label : ]
<b>case</b> expression <b>is</b>
case_statement_alternative
{ case_statement_alternative }
<b> end case</b> [ <i>case</i>_label ]<b> </b>;
case_statement_alternative ::=
<b>when</b> choices =>
sequence_of_statements
</pre>
<p>The expression must be of a discrete type, or of a one-dimensional array type whose element base type is a character type. This type must be determinable independently of the context in which the expression occurs, but using the fact that the expression must be of a discrete type or a one-dimensional character array type. Each choice in a case statement alternative must be of the same type as the expression; the list of choices specifies for which values of the expression the alternative is chosen.
<p>If the expression is the name of an object whose subtype is locally static,whether a scalar type or an array type, then each value of the subtype must be represented once and only once in the set of choices of the case statement, and no other value is allowed; this rule is likewise applied if the expression is a qualified expression or type conversion whose type mark denotes a locally static subtype, or if the expression is a call to a function whose return type mark denotes a locally static subtype.
<p>If the expression is of a one-dimensional character array type, then the expression must be one of the following:
<ul>
<p>-- The name of an object whose subtype is locally static
<p>-- An indexed name whose prefix is one of the members of this list and whose indexing expressions are locally static expressions
<p>-- A slice name whose prefix is one of the members of this list and whose discrete range is a locally static discrete range
<p>-- A function call whose return type mark denotes a locally static subtype
<p>-- A qualified expression or type conversion whose type mark denotes a locally static subtype
</ul>
<p>In such a case, each choice appearing in any of the case statement alternatives must be a locally static expression whose value is of the same length as that of the case expression. It is an error if the element subtype of the one-dimensional character array type is not a locally static subtype.
<p>For other forms of expression, each value of the (base) type of the expression must be represented once and only once in the set of choices, and no other value is allowed.
<p>The simple expression and discrete ranges given as choices in a case statement must be locally static. A choice defined by a discrete range stands for all values in the corresponding range. The choice <b>others</b> is only allowed for the last alternative and as its only choice; it stands for all values(possibly none) not given in the choices of previous alternatives. An element simple name (see <a href = "1076_7.HTM#7.3.2"> 7.3.2 </a> ) is not allowed as a choice of a case statement alternative.
<p>If a label appears at the end of a case statement, it must repeat the case label.
<p>The execution of a case statement consists of the evaluation of the expression followed by the execution of the chosen sequence of statements.
<h4>NOTES</h4>
<p>1--The execution of a case statement chooses one and only one alternative,since the choices are exhaustive and mutually exclusive. A qualified expression whose type mark denotes a locally static subtype can often be used as the expression of a case statement to limit the number of choices that need be explicitly specified.
<p>2--An <b>others</b> choice is required in a case statement if the type of the expression is the type <i>universal_integer</i> (for example, if the expression is an integer literal), since this is the only way to cover all values of the type <i>universal_integer.</i>
<p>3--Overloading the operator "=" has no effect on the semantics of case statement execution.
<h2><a name="8.9"> <a href = "1076_8.HTM#8.9"> 8.9 </a> Loop statement</a></h2>
<p>A loop statement includes a sequence of statements that is to be executed repeatedly, zero or more times.
<pre> loop_statement ::=
[ <i>loop</i>_label : ]
[ iteration_scheme ] <b>loop</b>
sequence_of_statements
<b>end loop</b> [ <i>loop</i>_label ] ;
iteration_scheme ::=
<b>while</b> condition
| <b>for</b> <i>loop</i>_parameter_specification
parameter_specification ::=
identifier <b>in</b> discrete_range
</pre>
<p>If a label appears at the end of a loop statement, it must repeat the label at the beginning of the loop statement.
<p>Execution of a loop statement is complete when the loop is left as a consequence of the completion of the iteration scheme (see below), if any, or the execution of a next statement, an exit statement, or a return statement.
<p>A loop statement without an iteration scheme specifies repeated execution of the sequence of statements.
<p>For a loop statement with a <b>while</b> iteration scheme, the condition is evaluated before each execution of the sequence of statements; if the value of the condition is TRUE, the sequence of statements is executed; if FALSE, the iteration scheme is said to be <i>complete</i> and the execution of the loop statement is complete.
<p>For a loop statement with a <b>for</b> iteration scheme, the loop parameter specification is the declaration of the <i>loop parameter</i> with the given identifier. The loop parameter is an object whose type is the base type of the discrete range. Within the sequence of statements, the loop parameter is a constant. Hence, a loop parameter is not allowed as the target of an assignment statement. Similarly, the loop parameter must not be given as an actual corresponding to a formal of mode <b>out</b> or <b>inout</b> in an association list.
<p>For the execution of a loop with a <b>for</b> iteration scheme, the discrete range is first evaluated. If the discrete range is a null range, the iteration scheme is said to be <i>complete</i> and the execution of the loop statement is therefore complete; otherwise, the sequence of statements is executed once for each value of the discrete range (subject to the loop not being left as a consequence of the execution of a next statement, an exit statement, or a return statement), after which the iteration scheme is said to be <i>complete</i>. Prior to each such iteration, the corresponding value of the discrete range is assigned to the loop parameter. These values are assigned in left-to-right order.
<p>NOTE--A loop may be left as the result of the execution of a next statement if the loop is nested inside of an outer loop and the next statement has a loop label that denotes the outer loop.
<h2><a name="8.10"> <a href = "1076_8.HTM#8.10"> 8.10 </a> Next statement</a></h2>
<p>A next statement is used to complete the execution of one of the iterations of an enclosing loop statement (called "loop" in the following text). The completion is conditional if the statement includes a condition.
<pre> next_statement ::=
[ label : ] <b>next</b> [ <i>loop</i>_label ] [ <b>when</b> condition ] ;
</pre>
<p>A next statement with a loop label is only allowed within the labeled loop and applies to that loop; a next statement without a loop label is only allowed within a loop and applies only to the innermost enclosing loop (whether labeled or not).
<p>For the execution of a next statement, the condition, if present, is first evaluated. The current iteration of the loop is terminated if the value of the condition is TRUE or if there is no condition.
<h2><a name="8.11"> <a href = "1076_8.HTM#8.11"> 8.11 </a> Exit statement</a></h2>
<p>An exit statement is used to complete the execution of an enclosing loop statement (called "loop" in the following text). The completion is conditional if the statement includes a condition.
<pre> exit_statement ::=
[ label : ] <b>exit</b> [ <i>loop</i>_label ] [ <b>when</b> condition ] ;
</pre>
<p>An exit statement with a loop label is only allowed within the labeled loop and applies to that loop; an exit statement without a loop label is only allowed within a loop and applies only to the innermost enclosing loop (whether labeled or not).
<p>For the execution of an exit statement, the condition, if present, is first evaluated. Exit from the loop then takes place if the value of the condition is TRUE or if there is no condition.
<h2><a name="8.12"> <a href = "1076_8.HTM#8.12"> 8.12 </a> Return statement</a></h2>
<p>A return statement is used to complete the execution of the innermost enclosing function or procedure body.
<pre> return_statement ::=
[ label : ] <b>return</b> [ expression ] ;
</pre>
<p>A return statement is only allowed within the body of a function or procedure,and it applies to the innermost enclosing function or procedure.
<p>A return statement appearing in a procedure body must not have an expression. A return statement appearing in a function body must have an expression.
<p>The value of the expression defines the result returned by the function. The type of this expression must be the base type of the type mark given after the reserved word <b>return</b> in the specification of the function. It is an error if execution of a function completes by any means other than the execution of a return statement.
<p>For the execution of a return statement, the expression (if any) is first evaluated and a check is made that the value belongs to the result subtype. The execution of the return statement is thereby completed if the check succeeds; so also is the execution of the enclosing subprogram. An error occurs at the place of the return statement if the check fails.
<h4>NOTES</h4>
<p>1--If the expression is either a numeric literal, or an attribute that yields a result of type <i>universal_integer</i> or <i>universal_real</i>, then an implicit conversion of the result is performed.
<p>2--If the return type mark of a function denotes a constrained array subtype,then no implicit subtype conversions are performed on the values of the expressions of the return statements within the subprogram body of that function. Thus, for each index position of each value, the bounds of the discrete range must be the same as the discrete range of the return subtype,and the directions must be the same.
<h2><a name="8.13"> <a href = "1076_8.HTM#8.13"> 8.13 </a> Null statement</a></h2>
<p>A null statement performs no action.
<pre> null_statement ::=
[ label : ] <b>null</b> ;
</pre>
<p>The execution of the null statement has no effect other than to pass on to the next statement.
<p>NOTE--The null statement can be used to specify explicitly that no action is to be performed when certain conditions are true, although it is never mandatory for this (or any other) purpose. This is particularly useful in conjunction with the case statement, in which all possible values of the case expression must be covered by choices: for certain choices, it may be that no action is required.
<HR>
<a href="../../HTML/HOMEPG.HTM"><img src="HP.GIF" border=0></a>
<a href="1076_TOC.HTM"><img src="TOP.GIF" BORDER=0></a>
<a href="1076_7.HTM"><img src="LEFT.GIF" BORDER=0></a>
<a href="1076_9.HTM"><img src="RIGHT.GIF" BORDER=0></a>
</body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -