<< Click to Display Table of Contents >> Navigation: User guide > Go to > Branching |
In Data and Tables Stages, executing the FINISH command causes execution to return to START in the current Stage, as long as there is still some data to be read.
Each Stage is normally executed command by command , in the order they appear in the CL script. There are commands that transfer control from the current command to a command other than the next one. This is known as "branching". The commands are: IF, ELSE, UL, GO TO, FILTER, GO OUT TO, GO BACK, and READ.
The IF, ELSE and UL commands cause execution of one or more commands following to be dependent on whether a logical expression is true or false.
The GO TO command allows you to branch round a set of commands, or to the end of processing for the current record; it can be executed conditionally (following IF or UL).
The FILTER command combines the UL and GO TO concepts (branches on a test).
The GO OUT TO command allows you to branch to another section of code automatically saving the branch point, so that GO BACK can be used to return after executing the external section to the point immediately after the GO OUT TO. This facility can be thought of as providing a "subroutine" effect.
The READ command may transfer control to another section of code when the end of a questionnaire is encountered, or when the end of the input file is encountered.
Finally, there are "code loop" branches created automatically by CL, to organise fast processing of the data when executing a Tables Stage - you have no control over these. Run Control Parameter NOLOOP suppresses the creation of code loops.
There is no limit on the number of branches in a CL script, but only 32000 internal positions are allowed, see next section on destinations .
Examples of filtered code:
if $ival/>0, ds $sval=$ival/1-5,>5,
if $area/2, then,
dm $area2=$123/1,2,
ds $also=$124/5..9,
endif,
ul $area/2, then,
dm $not2=$127/1,2,
endif,