home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / lrm / chap05.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  30.2 KB  |  1,454 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. The following document is a draft  of  the  corresponding  chapter  of  the
  7. version  23  the  Ada  Reference  Manual  produced  in response to the Ansi
  8. Canvass.  It is given a limited circulation  to  Ada  implementers  and  to
  9. other groups contributing comments (according to the conventions defined in
  10. RRM.comments).  This draft should not be referred to in any publication.
  11.  
  12.  
  13.  
  14.                       ANSI-RM-05.v23 - Draft Chapter
  15.  
  16.                                5  Statements
  17.  
  18.                                  83-02-11
  19.  
  20. This version has addressed comments up to #5795
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.                                5. Statements
  78.  
  79.  
  80.  
  81. A  statement  defines  an  action  to be performed;  the process by which a
  82. statement achieves its action is called execution of the statement.
  83.  
  84. This chapter describes the general  rules  applicable  to  all  statements.
  85. Some  specific  statements are discussed in later chapters.  Procedure call
  86. statements are described in Chapter 6 on subprograms.  Entry  call,  delay,
  87. accept,  select,  and abort statements are described in Chapter 9 on tasks.
  88. Raise statements are described  in  Chapter  11  on  exceptions,  and  code
  89. statements  in Chapter 13.  The remaining forms of statements are presented
  90. in this chapter.
  91.  
  92. References:  abort statement 9.10, accept  statement  9.5,  code  statement
  93. 13.8,  delay  statement  9.6,  entry  call  statement  9.5,  procedure call
  94. statement 6.4, raise statement 11.3, select statement 9.7
  95.  
  96.  
  97.  
  98.  
  99. 5.1  Simple and Compound Statements - Sequences of Statements
  100.  
  101.  
  102. A statement is either simple or compound.  A simple statement  encloses  no
  103. other  statement.   A  compound statement can enclose simple statements and
  104. other compound statements.
  105.  
  106.     sequence_of_statements ::= statement {statement}
  107.  
  108.     statement ::=
  109.        {label} simple_statement | {label} compound_statement
  110.  
  111.     simple_statement ::= null_statement
  112.        | assignment_statement | procedure_call_statement
  113.        | exit_statement       | return_statement
  114.        | goto_statement       | entry_call_statement
  115.        | delay_statement      | abort_statement
  116.        | raise_statement      | code_statement
  117.  
  118.     compound_statement ::=
  119.          if_statement         | case_statement
  120.        | loop_statement       | block_statement
  121.        | accept_statement     | select_statement
  122.  
  123.     label ::= <<label_simple_name>>
  124.  
  125.     null_statement ::= null;
  126.  
  127.  
  128.  
  129.                                   1
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. A statement is said to be labeled by the label name of  any  label  of  the
  139. statement.  A label name, and similarly a loop or block name, is implicitly
  140. declared  at  the  end  of  the  declarative  part  of  the innermost block
  141. statement, subprogram body, package body, task body, or generic  body  that
  142. encloses  the  labeled  statement,  the  named loop statement, or the named
  143. block statement, as the case may be.   For  a  block  statement  without  a
  144. declarative  part,  an implicit declarative part (and preceding declare) is
  145. assumed.
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                    5 - 2
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204. The implicit declarations for different label names, loop names, and  block
  205. names  occur  in  the  same  order  as  the beginnings of the corresponding
  206. labeled  statements,  loop  statements,  and  block  statements.   Distinct
  207. identifiers  must  be  used  for  all label, loop, and block names that are
  208. implicitly declared within the body of a  program  unit,  including  within
  209. block statements enclosed by this body, but excluding within other enclosed
  210. program  units  (a  program  unit is either a subprogram, a package, a task
  211. unit, or a generic unit).
  212.  
  213. Execution of a null statement has no other effect than to pass to the  next
  214. action.
  215.  
  216. The  execution of a sequence of statements consists of the execution of the
  217. individual statements in succession until the sequence is completed,  or  a
  218. transfer of control takes place.  A transfer of control is caused either by
  219. the execution of an exit, return, or goto statement;  by the selection of a
  220. terminate  alternative; by the raising of an exception;  or (indirectly) by
  221. the execution of an abort statement.
  222.  
  223. Examples of labeled statements:
  224.  
  225.     <<HERE>> <<ICI>> <<AQUI>> <<HIER>> null;
  226.  
  227.     <<AFTER>> X := 1;
  228.  
  229. Note:
  230.  
  231. The scope of a declaration starts at the place of  the  declaration  itself
  232. (see  8.2).   In  the case of a label, loop, or block name, it follows from
  233. this rule that the scope of the  implicit  declaration  starts  before  the
  234. first  explicit occurrence of the corresponding name, since this occurrence
  235. is either in a statement label, a loop statement, a block statement,  or  a
  236. goto  statement.   An  implicit declaration in a block statement may hide a
  237. declaration given in an outer program unit or block statement (according to
  238. the usual rules of hiding explained in section 8.3).
  239.  
  240. References:   abort  statement  9.10,  accept  statement  9.5,   assignment
  241. statement  5.2,  block  name  5.6, block statement 5.6, case statement 5.4,
  242. code statement 13.8, declaration 3.1, declarative part 3.9, delay statement
  243. 9.6, entry call statement 9.5, exception 11, exit  statement  5.7,  generic
  244. body 12.1, generic unit 12, goto statement 5.9, hiding 8.3, identifier 2.3,
  245. if  statement  5.3, implicit declaration 3.1, loop name 5.5, loop statement
  246. 5.5, package 7, package body 7.1, procedure  call  statement  6.4,  program
  247. unit  6,  raise  statement 11.3, raising of exceptions 11, return statement
  248. 5.8, scope 8.2, select  statement  9.7,  simple  name  4.1,  subprogram  6,
  249. subprogram  body  6.3,  task  9,  task  body  9.1, task unit 9.1, terminate
  250. alternative 9.7.1, terminated task 9.4
  251.  
  252.  
  253.  
  254.  
  255. 5.2  Assignment Statement
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                    5 - 3
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270. An assignment statement replaces the current value of a variable with a new
  271. value specified by an expression.  The named variable  and  the  right-hand
  272. side  expression must be of the same type;  this type must not be a limited
  273. type.
  274.  
  275.     assignment_statement ::=
  276.        variable_name := expression;
  277.  
  278. For the execution of an assignment statement, the  variable  name  and  the
  279. expression  are  first  evaluated, in some order that is not defined by the
  280. language.  A check is then made that the value of the expression belongs to
  281. the subtype of the variable, except in the case of a variable  that  is  an
  282. array  (the  assignment  then involves a subtype conversion as described in
  283. section 5.2.1).  Finally, the value of the expression becomes the new value
  284. of the variable.
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                    5 - 4
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336. The exception CONSTRAINT_ERROR is raised  if  the  above-mentioned  subtype
  337. check  fails;   in  such  a  case the current value of the variable is left
  338. unchanged.  If the variable is a subcomponent that depends on discriminants
  339. of an unconstrained record variable, then the execution of  the  assignment
  340. is  erroneous if the value of any of these discriminants is changed by this
  341. execution.
  342.  
  343. Examples:
  344.  
  345.     VALUE := MAX_VALUE - 1;
  346.     SHADE := BLUE;
  347.  
  348.     NEXT_FRAME(F)(M, N) := 2.5;        --  see 4.1.1
  349.     U := DOT_PRODUCT(V, W);            --  see 6.5
  350.  
  351.     WRITER := (STATUS => OPEN, UNIT => PRINTER, LINE_COUNT => 60);  -- see 3.7.3
  352.     NEXT_CAR.all := (72074, null);    --  see 3.8.1
  353.  
  354. Examples of constraint checks:
  355.  
  356.     I, J : INTEGER range 1 .. 10;
  357.     K    : INTEGER range 1 .. 20;
  358.      ...
  359.  
  360.     I := J;  --  identical ranges
  361.     K := J;  --  compatible ranges
  362.     J := K;  --  will raise the exception CONSTRAINT_ERROR if K > 10
  363.  
  364. Notes:
  365.  
  366. The values of the discriminants of an object designated by an access  value
  367. cannot  be  changed  (not  even by assigning a complete value to the object
  368. itself) since such objects, created by allocators, are  always  constrained
  369. (see 4.8);  however, subcomponents of such objects may be unconstrained.
  370.  
  371. If  the  right-hand  side  expression  is either a numeric literal or named
  372. number, or an attribute that yields a result of type  universal_integer  or
  373. universal_real, then an implicit type conversion is performed, as described
  374. in section 4.6.
  375.  
  376. The  determination  of  the type of the variable of an assignment statement
  377. may require consideration of the expression if the  variable  name  can  be
  378. interpreted  as  the  name  of  a  variable  designated by the access value
  379. returned by a function call, and similarly, as a component or slice of such
  380. a variable (see section 8.7 for the context of overload resolution).
  381.  
  382. References:  access type 3.8, allocator 4.8, array  3.6,  array  assignment
  383. 5.2.1,  component  3.6 3.7, constraint_error exception 11.1, designate 3.8,
  384. discriminant 3.7.1, erroneous 1.6, evaluation 4.5, expression 4.4, function
  385. call 6.4, implicit type conversion 4.6,  name  4.1,  numeric  literal  2.4,
  386. object  3.2,  overloading  6.6  8.7, slice 4.1.2, subcomponent 3.3, subtype
  387. 3.3, subtype  conversion  4.6,  type  3.3,  universal_integer  type  3.5.4,
  388. universal_real type 3.5.6, variable 3.2.1
  389.  
  390.  
  391.  
  392.  
  393.                                    5 - 5
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405. 5.2.1  Array Assignments
  406.  
  407.  
  408. If  the variable of an assignment statement is an array variable (including
  409. a slice variable), the value of the expression is implicitly  converted  to
  410. the  subtype  of the array variable;  the result of this subtype conversion
  411. becomes the new value of the array variable.
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                                    5 - 6
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. This means that the new value of each component of the  array  variable  is
  469. specified  by  the  matching  component  in  the  array  value  obtained by
  470. evaluation of the expression (see 4.5.2  for  the  definition  of  matching
  471. components).   The subtype conversion checks that for each component of the
  472. array variable there is a matching component in the array value,  and  vice
  473. versa.   The  exception CONSTRAINT_ERROR is raised if this check fails;  in
  474. such a case the value of each component  of  the  array  variable  is  left
  475. unchanged.
  476.  
  477. Examples:
  478.  
  479.     A : STRING(1 .. 31);
  480.     B : STRING(3 .. 33);
  481.      ...
  482.  
  483.     A := B;  --  same number of components
  484.  
  485.     A(1 .. 9)  := "tar sauce";
  486.     A(4 .. 12) := A(1 .. 9);  --  A(1 .. 12) = "tartar sauce"
  487.  
  488. Notes:
  489.  
  490. Array assignment is defined even in the case of overlapping slices, because
  491. the  expression  on  the right-hand side is evaluated before performing any
  492. component assignment.  In the above example, an implementation yielding A(1
  493. .. 12) = "tartartartar" would be incorrect.
  494.  
  495. The implicit subtype conversion described above for assignment to an  array
  496. variable  is performed only for the value of the right-hand side expression
  497. as a whole;  it is not performed for subcomponents that are  array  values.
  498.  
  499. References:   array  3.6,  assignment 5.2, constraint_error exception 11.1,
  500. matching array components 4.5.2, slice 4.1.2, subtype conversion 4.6,  type
  501. 3.3, variable 3.2.1
  502.  
  503.  
  504.  
  505.  
  506. 5.3  If Statements
  507.  
  508.  
  509. An if statement selects for execution one or none of the enclosed sequences
  510. of  statements, depending on the (truth) value of one or more corresponding
  511. conditions.
  512.  
  513.     if_statement ::=
  514.         if condition then
  515.           sequence_of_statements
  516.        {elsif condition then
  517.           sequence_of_statements}
  518.        [else
  519.           sequence_of_statements]
  520.         end if;
  521.  
  522.  
  523.  
  524.  
  525.                                    5 - 7
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.     condition ::= boolean_expression
  535.  
  536. An expression specifying a condition must be of a boolean type.
  537.  
  538. For the execution of an if statement, the condition specified after if, and
  539. any conditions specified after elsif, are evaluated in succession (treating
  540. a final else as elsif TRUE then),  until  one  evaluates  to  TRUE  or  all
  541. conditions  are  evaluated  and yield FALSE.  If one condition evaluates to
  542. TRUE, then the corresponding sequence of statements is executed;  otherwise
  543. none of the sequences of statements is executed.
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                    5 - 8
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. Examples:
  601.  
  602.  
  603.     if MONTH = DECEMBER and DAY = 31 then
  604.        MONTH := JANUARY;
  605.        DAY   := 1;
  606.        YEAR  := YEAR + 1;
  607.     end if;
  608.  
  609.     if LINE_TOO_SHORT then
  610.        raise LAYOUT_ERROR;
  611.     elsif LINE_FULL then
  612.        NEW_LINE;
  613.        PUT(ITEM);
  614.     else
  615.        PUT(ITEM);
  616.     end if;
  617.  
  618.     if MY_CAR.OWNER.VEHICLE /= MY_CAR then            --  see 3.8
  619.        REPORT ("Incorrect data");
  620.     end if;
  621.  
  622. References:  boolean type 3.5.3, evaluation 4.5, expression  4.4,  sequence
  623. of statements 5.1
  624.  
  625.  
  626.  
  627. 5.4  Case Statements
  628.  
  629.  
  630. A  case  statement  selects  for  execution  one of a number of alternative
  631. sequences of statements;  the chosen alternative is defined by the value of
  632. an expression.
  633.  
  634.     case_statement ::=
  635.        case expression is
  636.            case_statement_alternative
  637.           {case_statement_alternative}
  638.        end case;
  639.  
  640.     case_statement_alternative ::=
  641.        when choice {| choice } =>
  642.           sequence_of_statements
  643.  
  644. The expression must be of  a  discrete  type  which  must  be  determinable
  645. independently  of the context in which the expression occurs, but using the
  646. fact that the expression must be of a discrete type.  Moreover, the type of
  647. this expression must not be a generic formal type.  Each choice in  a  case
  648. statement alternative must be of the same type as the expression;  the list
  649. of  choices specifies for which values of the expression the alternative is
  650. chosen.
  651.  
  652. If the expression is the name of an object whose subtype  is  static,  then
  653. each  value  of  this subtype must be represented once and only once in the
  654. set of choices of the case statement, and no other value is allowed;   this
  655.  
  656.  
  657.                                    5 - 9
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666. rule  is  likewise  applied  if the expression is a qualified expression or
  667. type conversion whose type mark denotes a static subtype.   Otherwise,  for
  668. other  forms of expression, each value of the (base) type of the expression
  669. must be represented once and only once in the set of choices, and no  other
  670. value is allowed.
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.                                   5 - 10
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732. The  simple  expressions  and  discrete  ranges  given as choices in a case
  733. statement must be static.  A choice defined by a discrete range stands  for
  734. all  values  in the corresponding range (none if a null range).  The choice
  735. others is only allowed for the last alternative and as its only choice;  it
  736. stands for all values (possibly none) not given in the choices of  previous
  737. alternatives.  A component simple name is not allowed as a choice of a case
  738. statement alternative.
  739.  
  740. The  execution  of  a  case  statement  consists  of  the evaluation of the
  741. expression followed by the execution of the chosen sequence of  statements.
  742.  
  743. Examples:
  744.  
  745.     case SENSOR is
  746.        when ELEVATION  => RECORD_ELEVATION(SENSOR_VALUE);
  747.        when AZIMUTH    => RECORD_AZIMUTH  (SENSOR_VALUE);
  748.        when DISTANCE   => RECORD_DISTANCE (SENSOR_VALUE);
  749.        when others     => null;
  750.     end case;
  751.  
  752.     case TODAY is
  753.        when MON        => COMPUTE_INITIAL_BALANCE;
  754.        when FRI        => COMPUTE_CLOSING_BALANCE;
  755.        when TUE .. THU => GENERATE_REPORT(TODAY);
  756.        when SAT .. SUN => null;
  757.     end case;
  758.  
  759.     case BIN_NUMBER(COUNT) is
  760.        when 1      => UPDATE_BIN(1);
  761.        when 2      => UPDATE_BIN(2);
  762.        when 3 | 4  =>
  763.           EMPTY_BIN(1);
  764.           EMPTY_BIN(2);
  765.        when others => raise ERROR;
  766.     end case;
  767.  
  768. Notes:
  769.  
  770. The  execution  of  a  case statement chooses one and only one alternative,
  771. since the choices are exhaustive and mutually exclusive.  Qualification  of
  772. the expression of a case statement by a static subtype can often be used to
  773. limit the number of choices that need be given explicitly.
  774.  
  775. An  others  choice  is  required  in  a  case statement if the  type of the
  776. expression is the type universal_integer (for example, if the expression is
  777. an integer literal), since this is the only way to cover all values of  the
  778. type universal_integer.
  779.  
  780. References:   base  type  3.3, choice 3.7.3, context of overload resolution
  781. 8.7, discrete type 3.5, expression 4.4, function call 6.4,  generic  formal
  782. type  12.1,  conversion  4.6, discrete type 3.5, enumeration literal 3.5.1,
  783. expression 4.4, name 4.1, object  3.2.1,  overloading  6.6  8.7,  qualified
  784. expression  4.7,  sequence  of  statements  5.1, static discrete range 4.9,
  785. static subtype 4.9, subtype 3.3, type 3.3, type conversion 4.6,  type  mark
  786. 3.3.2
  787.  
  788.  
  789.                                   5 - 11
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798. 5.5  Loop Statements
  799.  
  800.  
  801. A  loop  statement includes a sequence of statements that is to be executed
  802. repeatedly, zero or more times.
  803.  
  804.     loop_statement ::=
  805.        [loop_simple_name:]
  806.           [iteration_scheme] loop
  807.              sequence_of_statements
  808.            end loop [loop_simple_name];
  809.  
  810.     iteration_scheme ::= while condition
  811.        | for loop_parameter_specification
  812.  
  813.     loop_parameter_specification ::=
  814.        identifier in [reverse] discrete_range
  815.  
  816. If a loop statement has a loop simple name, this simple name must be  given
  817. both at the beginning and at the end.
  818.  
  819. A  loop  statement without an iteration scheme specifies repeated execution
  820. of the sequence of statements.  Execution of the loop statement is complete
  821. when the loop is left  as  a  consequence  of  the  execution  of  an  exit
  822. statement, or as a consequence of some other transfer of control (see 5.1).
  823.  
  824. For  a  loop  statement  with  a  while  iteration scheme, the condition is
  825. evaluated before each execution of the  sequence  of  statements;   if  the
  826. value  of the condition is TRUE, the sequence of statements is executed, if
  827. FALSE the execution of the loop statement is complete.
  828.  
  829. For a loop statement with  a  for  iteration  scheme,  the  loop  parameter
  830. specification  is  the  declaration  of  the  loop parameter with the given
  831. identifier.  The loop parameter is an object whose type is the base type of
  832. the discrete range (see 3.6.1).  Within the  sequence  of  statements,  the
  833. loop parameter is a constant.  Hence a loop parameter is not allowed as the
  834. (left-hand  side)  variable of an assignment statement.  Similarly the loop
  835. parameter must not be given as an out or in out parameter of a procedure or
  836. entry call statement, or as an in out parameter of a generic instantiation.
  837.  
  838. For the execution of a loop statement with a for iteration scheme, the loop
  839. parameter specification is first elaborated.  This elaboration creates  the
  840. loop parameter and evaluates the discrete range.
  841.  
  842. If  the discrete range is a null range, the execution of the loop statement
  843. is complete.  Otherwise, the sequence of statements is  executed  once  for
  844. each  value  of the discrete range (subject to the loop not being left as a
  845. consequence of the execution of an exit statement or as  a  consequence  of
  846. some  other  transfer  of  control).   Prior  to  each  such iteration, the
  847. corresponding  value  of  the  discrete  range  is  assigned  to  the  loop
  848. parameter.   These  values  are  assigned  in  increasing  order unless the
  849. reserved word reverse is present, in which case the values are assigned  in
  850. decreasing order.
  851.  
  852.  
  853.  
  854.  
  855.                                   5 - 12
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. Example of a loop statement without an iteration scheme:
  865.  
  866.     loop
  867.        GET(CURRENT_CHARACTER);
  868.        exit when CURRENT_CHARACTER = '*';
  869.     end loop;
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.                                   5 - 13
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930. Example of a loop statement with a while iteration scheme:
  931.  
  932.     while BID(N).PRICE < CUT_OFF.PRICE loop
  933.        RECORD_BID(BID(N).PRICE);
  934.        N := N + 1;
  935.     end loop;
  936.  
  937.  
  938. Example of a loop statement with a for iteration scheme:
  939.  
  940.     for J in BUFFER'RANGE loop     --  legal even with a null range
  941.        if BUFFER(J) /= SPACE then
  942.           PUT(BUFFER(J));
  943.        end if;
  944.     end loop;
  945.  
  946.  
  947. Example of a loop statement with a loop simple name:
  948.  
  949.     SUMMATION:
  950.        while NEXT /= HEAD loop       -- see 3.8
  951.           SUM  := SUM + NEXT.VALUE;
  952.           NEXT := NEXT.SUCC;
  953.        end loop SUMMATION;
  954.  
  955.  
  956. Notes:
  957.  
  958. The scope of a loop parameter extends from the loop parameter specification
  959. to  the end of the loop statement, and the visibility rules are such that a
  960. loop parameter is only visible within the sequence  of  statements  of  the
  961. loop.
  962.  
  963. The  discrete  range  of  a  for  loop  is evaluated just once.  Use of the
  964. reserved word reverse does not  alter  the  discrete  range,  so  that  the
  965. following  iteration  schemes  are  not  equivalent;   the first has a null
  966. range.
  967.  
  968.     for J in reverse 1 .. 0
  969.     for J in 0 .. 1
  970.  
  971. Loop names are also used in exit statements, and in expanded  names  (in  a
  972. prefix of the loop parameter).
  973.  
  974.  
  975. References:   actual  parameter  6.4.1, assignment statement 5.2, base type
  976. 3.3, bound of a range  3.5,  condition  5.3,  constant  3.2.1,  context  of
  977. overload  resolution  8.7,  conversion 4.6, declaration 3.1, discrete range
  978. 3.6.1, elaboration 3.1, entry call  statement  9.5,  evaluation  4.5,  exit
  979. statement  5.7,  expanded  name  4.1.3,  false boolean value 3.5.3, generic
  980. actual parameter 12.3, generic  instantiation  12.3,  goto  statement  5.9,
  981. identifier  2.3,  integer  type 3.5.4, null range 3.5, object 3.2.1, prefix
  982. 4.1, procedure call 6.4, raising  of  exceptions  11,  reserved  word  2.9,
  983. return  statement  5.8,  scope 8.2, sequence of statements 5.1, simple name
  984. 4.1,  terminate  alternative  9.7.1,  true  boolean  value   3.5.3   3.5.4,
  985.  
  986.  
  987.                                   5 - 14
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996. visibility 8.3
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.  
  1019.  
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.  
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.                                   5 - 15
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062. 5.6  Block Statements
  1063.  
  1064.  
  1065. A  block statement encloses a sequence of statements optionally preceded by
  1066. a declarative part and optionally followed by exception handlers.
  1067.  
  1068.     block_statement ::=
  1069.        [block_simple_name:]
  1070.           [declare
  1071.                declarative_part]
  1072.            begin
  1073.                sequence_of_statements
  1074.           [exception
  1075.                exception_handler
  1076.               {exception_handler}]
  1077.            end [block_simple_name];
  1078.  
  1079. If a block statement has a block simple name,  this  simple  name  must  be
  1080. given both at the beginning and at the end.
  1081.  
  1082. The  execution  of  a  block  statement  consists of the elaboration of its
  1083. declarative part (if any) followed by the  execution  of  the  sequence  of
  1084. statements.   If  the block statement has exception handlers, these service
  1085. corresponding exceptions that  are  raised  during  the  execution  of  the
  1086. sequence of statements (see 11.2).
  1087.  
  1088. Example:
  1089.  
  1090.     SWAP:
  1091.        declare
  1092.           TEMP : INTEGER;
  1093.        begin
  1094.           TEMP := V; V := U; U := TEMP;
  1095.        end SWAP;
  1096.  
  1097. Notes:
  1098.  
  1099. If  task  objects  are declared within a block statement whose execution is
  1100. completed, the block statement is not left until all  its  dependent  tasks
  1101. are terminated (see 9.4).  This rule applies also to a completion caused by
  1102. an exit, return, or goto statement;  or by the raising of an exception.
  1103.  
  1104. Within  a  block  statement,  the  block name can be used in expanded names
  1105. denoting local entities such as SWAP.TEMP in the above example  (see  4.1.3
  1106. (f)).
  1107.  
  1108. References:   declarative  part  3.9, dependent task 9.4, exception handler
  1109. 11.2, exit statement 5.7, expanded name 4.1.3, goto statement 5.9,  raising
  1110. of  exceptions 11, return statement 5.8, sequence of statements 5.1, simple
  1111. name 4.1, task object 9.2
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                   5 - 16
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128. 5.7  Exit Statements
  1129.  
  1130.  
  1131. An exit statement is used to complete the execution of  an  enclosing  loop
  1132. statement (called the loop in what follows);  the completion is conditional
  1133. if the exit statement includes a condition.
  1134.  
  1135.     exit_statement ::=
  1136.        exit [loop_name] [when condition];
  1137.  
  1138. An  exit  statement with a loop name is only allowed within the named loop,
  1139. and applies to that loop;  an exit statement without a loop  name  is  only
  1140. allowed within a loop, and applies to the innermost enclosing loop (whether
  1141. named or not).  Furthermore, an exit statement that applies to a given loop
  1142. must  not appear within a subprogram body, package body, task body, generic
  1143. body, or accept statement, if this construct  is  itself  enclosed  by  the
  1144. given loop.
  1145.  
  1146. For the execution of an exit statement, the condition, if present, is first
  1147. evaluated.   Exit from the loop then takes place if the value is TRUE or if
  1148. there is no condition.
  1149.  
  1150. Examples:
  1151.  
  1152.     for N in 1 .. MAX_NUM_ITEMS loop
  1153.        GET_NEW_ITEM(NEW_ITEM);
  1154.        MERGE_ITEM(NEW_ITEM, STORAGE_FILE);
  1155.        exit when NEW_ITEM = TERMINAL_ITEM;
  1156.     end loop;
  1157.  
  1158.     MAIN_CYCLE:
  1159.        loop
  1160.           --  initial statements
  1161.           exit MAIN_CYCLE when FOUND;
  1162.           --  final statements
  1163.        end loop MAIN_CYCLE;
  1164.  
  1165. Note:
  1166.  
  1167. Several nested loops can be exited by an  exit  statement  that  names  the
  1168. outer loop.
  1169.  
  1170. References:   accept  statement 9.5, condition 5.3, evaluation 4.5, generic
  1171. body 12.1, loop name 5.5, loop statement 5.5, package body 7.1,  subprogram
  1172. body 6.3, true boolean value 3.5.3
  1173.  
  1174.  
  1175.  
  1176.  
  1177. 5.8  Return Statements
  1178.  
  1179.  
  1180. A  return  statement  is  used  to  complete the execution of the innermost
  1181. enclosing function, procedure, or accept statement.
  1182.  
  1183.  
  1184.  
  1185.                                   5 - 17
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.     return_statement ::= return [expression];
  1195.  
  1196. A return statement is only allowed within  the  body  of  a  subprogram  or
  1197. generic  subprogram,  or  within  an  accept  statement, and applies to the
  1198. innermost (enclosing) such construct;  a return statement  is  not  allowed
  1199. within  the  body  of a task unit,  package, or generic package enclosed by
  1200. this construct (on  the  other  hand,  it  is  allowed  within  a  compound
  1201. statement  enclosed  by  this  construct  and,  in  particular,  in a block
  1202. statement).
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.  
  1216.  
  1217.  
  1218.  
  1219.  
  1220.  
  1221.  
  1222.  
  1223.  
  1224.  
  1225.  
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                   5 - 18
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260. A return statement for an accept statement or for the body of  a  procedure
  1261. or  generic  procedure  must not include an expression.  A return statement
  1262. for the body of a function or generic function must include an  expression.
  1263.  
  1264. The  value  of  the expression defines the result returned by the function.
  1265. The type of this expression must be the base type of the  type  mark  given
  1266. after  the  reserved  word  return  in the specification of the function or
  1267. generic function (this type mark defines the result subtype).
  1268.  
  1269. For the execution of a return statement, the expression (if any)  is  first
  1270. evaluated and a check is made that the value belongs to the result subtype.
  1271. The  execution  of  the  return statement is thereby completed if the check
  1272. succeeds;  so also is the execution of the  subprogram  or  of  the  accept
  1273. statement.   The  exception  CONSTRAINT_ERROR is raised at the place of the
  1274. return statement if the check fails.
  1275.  
  1276. Examples:
  1277.  
  1278.     return;                         -- in a procedure
  1279.     return KEY_VALUE(LAST_INDEX);   -- in a function
  1280.  
  1281. Note:
  1282.  
  1283. If the expression is either a  numeric  literal  or  named  number,  or  an
  1284. attribute that yields a result of type universal_integer or universal_real,
  1285. then  an  implicit  conversion  of  the result is performed as described in
  1286. section 4.6.
  1287.  
  1288.  
  1289. References:  accept  statement  9.5,  attribute  A,  block  statement  5.6,
  1290. constraint_error   exception  11.1,  expression  4.4,  function  body  6.3,
  1291. function call 6.4, generic body 12.1, implicit type conversion  4.6,  named
  1292. number  3.2,  numeric  literal  2.4,  package body 7.1, procedure body 6.3,
  1293. reserved word 2.9, result subtype  6.1,  subprogram  body  6.3,  subprogram
  1294. specification   6.1,   subtype   3.3,  task  body  9.1,  type  mark  3.3.2,
  1295. universal_integer type 3.5.4, universal_real type 3.5.6
  1296.  
  1297.  
  1298.  
  1299. 5.9  Goto Statements
  1300.  
  1301.  
  1302. A goto statement specifies  an  explicit  transfer  of  control  from  this
  1303. statement to a target statement named by a label.
  1304.  
  1305.     goto_statement ::= goto label_name;
  1306.  
  1307. The  innermost  sequence  of  statements that encloses the target statement
  1308. must also enclose the goto statement (note that the goto statement can be a
  1309. statement of an inner sequence).   Furthermore,  if  a  goto  statement  is
  1310. enclosed  by  an  accept  statement or the body of a program unit, then the
  1311. target statement must not be outside this enclosing construct;  conversely,
  1312. it follows from the previous rule that if the target statement is  enclosed
  1313. by such a construct, then the goto statement cannot be outside.
  1314.  
  1315.  
  1316.  
  1317.                                   5 - 19
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326. The  execution  of  a  goto statement transfers control to the named target
  1327. statement.
  1328.  
  1329.  
  1330.  
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338.  
  1339.  
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355.  
  1356.  
  1357.  
  1358.  
  1359.  
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372.  
  1373.  
  1374.  
  1375.  
  1376.  
  1377.  
  1378.  
  1379.  
  1380.  
  1381.  
  1382.  
  1383.                                   5 - 20
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392. Note:
  1393.  
  1394. The above rules allow transfer of control to a statement  of  an  enclosing
  1395. sequence  of  statements  but  not  the  reverse.  Similarly, they prohibit
  1396. transfers of control such as between alternatives of a case  statement,  if
  1397. statement,  or  select  statement;  between exception handlers;  or from an
  1398. exception handler of a frame back to the sequence  of  statements  of  this
  1399. frame.
  1400.  
  1401. Example:
  1402.  
  1403.  
  1404.     <<COMPARE>>
  1405.        if A(I) < ELEMENT then
  1406.           if LEFT(I) /= 0 then
  1407.              I := LEFT(I);
  1408.              goto COMPARE;
  1409.           end if;
  1410.           --  some statements
  1411.        end if;
  1412.  
  1413.  
  1414. References:  accept statement 9.5, block statement 5.6, case statement 5.4,
  1415. compound  statement  5.1,  exception handler 11.2, frame 11.2, generic body
  1416. 12.1, if statement 5.3, label 5.1, package body 7.1, program unit 6, select
  1417. statement 9.7, sequence of statements 5.1, statement 5.1,  subprogram  body
  1418. 6.3, task body 9.1, transfer of control 5.1
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                                   5 - 21
  1450.  
  1451.  
  1452.  
  1453.  
  1454.