pTAL Reference Manual (G06.24+, H06.09+, J06.03+)
RETURN 10;
END;
INT PROC p2; ! p2 has optimized FOR statement
BEGIN
USE i;
y := 0;
FOR i := 1 to q() DO ... ; ! q is called 1 time
! i=10 here
RETURN x; ! p2 returns 1
END;
GOTO
The GOTO statement unconditionally transfers control to a labeled target statement.
label-name
is the label that precedes the target statement (see Labels in Procedures (page 273)).
A GOTO statement can be either local or nonlocal.
Topics:
• Local (page 215)
• Nonlocal (page 215) (not recommended)
• GOTO and Target Statements With Different Trapping States (page 216)
Local
If the GOTO statement and the target statement are in the same procedure or in the same
subprocedure, the GOTO statement is local.
Example 160 Local GOTO Statement
PROC p
BEGIN
LABEL calc_a; ! Declare local label
INT a;
INT b := 5;
calc_a : ! Place label at local statement
a := b * 2;
! Lots of code
GOTO calc_a; ! Local branch to local label
END;
Nonlocal
NOTE: Nonlocal GOTO statements are inefficient and not recommended.
If the GOTO statement is in a subprocedure and the target statement is in the enclosing procedure,
the GOTO statement is nonlocal.
Example 161 Nonlocal GOTO Statement
int global_var;
proc p;
begin
GOTO 215