Language Reference


LINK Statement

LINK (label);

  • statements;

  • label:statements;

  • RETURN ;

The LINK statement provides a way of calling a group of statements as if they were defined as a subroutine. When the LINK statement is executed, the program jumps immediately to the statement with the given label and begins executing statements from that point as it does for the GOTO statement . However, when the program executes a RETURN statement , the program returns to the statement that immediately follows the LINK statement, which is different behavior than the GOTO statement.

The LINK statement can be used only inside modules and DO groups. LINK statements can be nested within other LINK statements to any level. A RETURN statement without a LINK statement is executed the same as the STOP statement .

Instead of using a LINK statement, you can define a module and call the module by using a RUN statement .

An example that uses the LINK statement follows:

start a;
   x=1;
   y=2;
   link sum1; /* go to label; execute until return stmt */
   print z;
   stop;
   sum1:
      z=x+y;
   return;
finish a;

run a;

Figure 24.192: Result of Linking to a Group of Statements

z
3