Label data and LABEL attribute
A label is a label constant or the value of a label variable.
If a list of label constants is given, the variable must always have as its value a member of that list, and the label constants in the list must be known in the block containing the label declaration. The parenthesized list of label constants can be used in a LABEL attribute specification for a label array.
A label constant is a name written as the label prefix of a statement (other than PROCEDURE, ENTRY, PACKAGE, or FORMAT) so that during execution, program-control can be transferred to that statement through a reference to it. (Statements discusses the syntax of the label prefix.)
For example, in the following line of code, Abcde is
a label constant.
Abcde: Miles = Speed*Hours;
The labelled statement can be executed either by normal sequential execution of instructions or by using the GO TO statement to transfer control to it from some other point in the program.
A label variable can have another label variable or a label constant assigned to it. When such an assignment is made, the environment of the source label is assigned to the target. If you declare a static array of labels to have initial values, the array is treated as nonassignable.
A label variable used in a GO TO statement must have as its value a label constant that is used in a block that is active at the time the GO TO is executed. Consider the following example:
declare Lbl_x label;
Lbl_a: statement;
.
.
.
Lbl_b: statement;
.
.
.
Lbl_x = Lbl_a;
.
.
.
go to Lbl_x;
Lbl_a and Lbl_b are label constants,
and Lbl_x is a label variable. By assigning Lbl_a to Lbl_x,
the statement GO TO Lbl_x transfers control to the Lbl_a statement.
Elsewhere, the program can contain a statement assigning Lbl_b to Lbl_x.
Then, any reference to Lbl_x would be the same as
a reference to Lbl_b. This value of Lbl_x is
retained until another value is assigned to it.
If a label variable has an invalid value, detection of such an
error is not guaranteed. In the following example, transfer is made
to a particular element of the array Z based on the
value of I.
go to Z(I);
.
.
.
Z(1): if X = Y then return;
.
.
.
Z(2): A = A + B + C * D;
.
.
.
Z(3): A = A + 10;
If Z(2) is omitted, GO TO Z(I) when I=2 raises
the ERROR condition. GO TO Z(I) when I < LBOUND(Z) or I >
HBOUND(Z) causes unpredictable results if the SUBSCRIPTRANGE
condition is disabled.
