The &GOTO control statement can be coded wherever an executable
statement is permitted in anEXEC procedure. One of its common uses is
in conjunction with the &IF control statement. For example, in the
statement:
&IF&INDEX EQ 0 &GOTO -ERROR the branch to the statement labeled -ERROR is taken when the value of
the&INDEX special variable is zerOe Otherwise, control passes to the
next sequential statement in theEXEC proceduie.
An&GOTO statement can also stand alone as an EXEC control statement. When coded as such, it forces an unconditional branch to the specified
location. For example, you might create anEXEC that has several
execution paths, each of which terminates with an&GOTO state.ent
leading to aco.mon exit routine: -PATHl &CONTINUE &GOTO -EXIT -PATH2 &CONTINUE &GOTO -EXIT &PATH3 &CONTINUE -EXIT &CONTINUE Iou can use the &GOTO control statement to establish a loop. For
example:&GLOBALl = &GLOBAL1 + 1 &TIPE ENTER NUMBER: &READ VARS &NEXT SIF .&NEXT = • &GOTO -FINIS
&IF&GLOBAL1 = 2 &TOTAL = 0 &TOTAL = &TOTAL • &NEXT &GOTO TOP -FINIS STIPE TOTAL IS &TOTAL In this EXEC example, all of the statements, through the SGOTO TOP statement, are executed repeatedly until a null line is entered in
response to the prompting message. Then, the branch is taken to the
label -FINIS and the total is typed.
Note the use of
example. The&GLOBALn an initial value of 1.
the special variable&GLOBAL1 in the
special variables are self-initializing
preceding
and haveWhen an EXEC procedure processes an &GOTO statement, and searches for a
given label or line number, the scan begins on the line following the&GOTO statement, proceeds to the botto. of the file, then wraps around
to the top of the file and continues to the line immediately preceding
278IBM VM/370 CMS User's Guide
statement is permitted in an
in conjunction with the &IF control statement. For example, in the
statement:
&IF
the
next sequential statement in the
An
location. For example, you might create an
execution paths, each of which terminates with an
leading to a
example:
&IF
response to the prompting message. Then, the branch is taken to the
label -FINIS and the total is typed.
Note the use of
example. The
the special variable
special variables are self-initializing
preceding
and have
given label or line number, the scan begins on the line following the
to the top of the file and continues to the line immediately preceding
278