Open topic with navigation
WTSupported in traditional Synergy on Windows
WNSupported in Synergy .NET on Windows
USupported on UNIX
VSupported on OpenVMS
GOTO(label[, …]), selector
A single statement label or a list of one or more statement labels that exist in the program. The first label is element 1, the second is element 2, and so forth.
An expression whose value selects the corresponding element from the list of labels. (n)
The GOTO statement transfers execution control to a specified label. The unconditional form of this statement specifies a single label. The computed form of this statement specifies a list of labels and a selection expression whose value indicates the desired label.
In the computed form of the GOTO statement, if selector is between 1 and the number of elements in label, the corresponding element is selected and control immediately transfers to the to the named label. However, if the value is less than 1 or more than the number of elements in label, no element is selected and execution continues with the statement following the GOTO.
This subroutine takes a result value to decide which code section to process. If the routine decide returns a result value of 1, control is transferred to lbl1. A value of 2, 3, or 4 transfers control to labels lbl2, lbl3, or lbl4, respectively. Any other value generates the message “… invalid result.”
subroutine choice a_data ,a record result ,d2
proc loop, xcall decide(a_data, result) goto (lbl1, lbl2, lbl3, lbl4), result writes(TTCHN, "... invalid result") goto loop
writes(TTCHN, "Processing result #1") goto loop lbl2, writes(TTCHN, "Processing result #2") goto loop
lbl3, writes(TTCHN, "Processing result #3") goto loop
lbl4, xreturn endsubroutine subroutine decide a_data ,a result ,d
proc display(TTCHN, "Result value? ") reads(TTCHN, %a(result)) return
We recommend that you not use GOTO when the logic can be written using structured statements instead. For example, we could rewrite the above code as follows:
subroutine choice a_data ,a external function decide ,d
proc repeat begin using %decide select begincase (1), writes(TTCHN, "Processing result #1") (2), writes(TTCHN, "Processing result #2") (3), writes(TTCHN, "Processing result #3") (4), xreturn writes(TTCHN, "... invalid result") endusing end endsubroutine