Previous Topic Next topic Print topic


Statements that Alter the Order of Execution

Statements are typically executed in the order in which they are written; however, certain statements control the order of execution of the program. These statements are GOTO (used with a statement label), IF, and DO.

The GOTO statement causes control to be transferred to a labelled statement in the current procedure or in another active procedure. Its general form is:

GOTO label–reference[OTHERWISE];

or

GO TO label–reference[OTHERWISE];

where:

label–reference is a label constant or an expression that, when evaluated, yields a label value. (A label value denotes a statement in the program.) For example:

A = 5; 
   GOTO L2;
L1:
   B = 7;
     .
     .
     .
L2:
   B = 4;

In this example, A is assigned 5 and B is assigned 4. The statements beginning with label L1 can be executed only if a GOTO statement transfers control to the label L1.

Although labels are a convenient means to represent a specific location in a program, programs that contain many labels are generally more difficult to read and modify. The use of labels and GOTOs can be avoided or minimized by using the compound statements IF and DO to control the order of statement execution.

The DO statement causes all statements between the DO statement and its corresponding END statement to be executed a number of times as determined by the form of the DO statement.

Previous Topic Next topic Print topic