• No results found

The Discrete DO FOR Statement.

In document hal s language specification pdf (Page 113-116)

DECLARE X ARRAY(2,3) SCALAR;

SUBBIT 33 TO 64 (P) bits 33 through 64 of the machine representation of P look like a 32-bit variable

7.6 The DO…END Statement Group.

7.6.4 The Discrete DO FOR Statement.

The discrete DO FOR statement causes execution of the sequence of <statement>s in a group once for each of a list of values of a “loop variable”. The presence of a WHILE or UNTIL clause can be used to cause such execution to be dependent on some condition being satisfied.

SYNTAX:

Figure 7-11 discrete DO FOR statement - #53 SEMANTIC RULES:

1. <arith var> is the loop variable of the DO FOR statement. It may be any unarrayed integer or scalar variable. The initial loop variable, determined after all required sub- scripting and NAME dereferencing, is used throughout.

2. The maximum number of times of execution of the group of <statement>s is the number of <arith exp>s in the assignment list.

3. <arith exp> is an unarrayed INTEGER or SCALAR expression.

4. At the beginning of each cycle of execution of the group the next <arith exp> in the list (starting from the leftmost) is evaluated and assigned to the loop variable. The assignment follows the relevant assignment statement rules given in Section 7.3. 5. Use of the WHILE or UNTIL clause causes continuation of cycling of execution to be

dependent on the value of <condition> or <bit exp>.

6. There is no semantic restriction or <condition>. <bit exp> must be boolean and unarrayed (i.e., of 1-bit length). The <condition> or <bit exp> is reevaluated every time the group of <statement>s is executed.

do statement arith exp arith var 53 label : = ; example: DO FOR I = 10, 20 WHILE J >0; condition bit exp DO FOR WHILE UNTIL ,

7. If the WHILE clause is used, cycling of execution is abandoned when the value of <condition> or <bit exp> becomes FALSE. The value is tested at the beginning of each cycle of execution after the assignment of the loop variable. This implies that if <condition> or <bit exp> is FALSE prior to the first cycle of execution of the group, then the group will not be executed at all.

8. If the UNTIL clause is used, cycling of execution is abandoned when the value of <condition> or <bit exp> becomes TRUE. The value is not tested before the first cycle of execution. On the second and all subsequent cycles of execution, the value is tested at the beginning of each cycle after the assignment of the loop variable. Use of the UNTIL version therefore always guarantees at least one cycle of execution. 7.6.5 The Iterative DO FOR Statement.

The iterative DO FOR statement is similar in intent and operation to the discrete DO FOR statement, except that the list of values that the loop variable may take on is replaced by an initial value, a final value, and an optional increment.

SYNTAX:

Figure 7-12 iterative DO FOR statement - #54 SEMANTIC RULES:

1. <arith var> is the loop variable of the DO FOR statement. It may be any unarrayed integer or scalar variable. The initial loop variable, determined after all required sub- scripting and NAME dereferencing, is used throughout.

2. Each <arith exp> is any unarrayed integer or scalar expression. All are evaluated prior to the first cycle of execution of the group.

do statement arith exp arith var 54 label : = ; example: DO FOR I = 1 TO 30 BY 2 UNTIL J < 0; condition bit exp arith exp arith exp DO FOR TO BY WHILE UNTIL

3. If a BY clause appears in the DO FOR statement, the value assigned to the loop variable prior to the Kth cycle of execution is equal to its value on the K-1th cycle plus

the value of <arith exp> following the BY keyword (the “increment”).

4. Assignment of values to the loop variable follows the relevant assignment rules given in Section 7.3. In particular, if the loop variable is of integer type, and an initial value or increment is of scalar type, the latter will be rounded to the nearest integer in the assignment process. The effect of the loop variable assignment is identical to that of an ordinary assignment statement: the loop variable will retain the last value

computed and assigned when the DO statement execution is completed.

5. After the value of the loop variable has been changed, it is checked against the value of the <arith exp> following the TO keyword (the “final value”).

6. If the sign of the increment is positive, the next cycle is permitted to proceed only if the current value of the loop variable is less than or equal to the final value.

7. If the sign of the increment is negative, the next cycle is permitted to proceed only if the current value of the loop variable is greater than or equal to the final value. 8. If the WHILE clause is used, cycling of execution is abandoned when the value of

<condition> or <bit exp> becomes FALSE. The value is tested at the beginning of each cycle of execution after the assignment of the loop variable. This implies that if <condition> or <bit exp> is FALSE prior to the first cycle of execution of the group, then the group will not be executed at all.

9. If the UNTIL clause is used, cycling of execution is abandoned when the value of <condition> or <bit exp> becomes TRUE. The value is not tested before the first cycle of execution. On the second and all subsequent cycles of execution, the value is tested at the beginning of each cycle after the assignment of the loop variable. Use of the UNTIL version therefore always guarantees at least one cycle of execution. 7.6.6 The END Statement.

The END statement closes a DO…END statement group. SYNTAX:

Figure 7-13 END statement - #55

end statement : 55 example: END LOOP; ; END label label

SEMANTIC RULES:

1. If <label> follows the END keyword, then it must match a <label> on the <do state- ment> opening the DO…END group.

2. The <end statement> is considered to be part of the group, in that if it is branched to from a <statement> within the group, then depending on the form of the opening <do statement>, another cycle of execution of the group may begin. The END statement closing a DO CASE is not counted as another case.

In document hal s language specification pdf (Page 113-116)