138
Labels are local to a function-which means they can only be used within that
function. Following are some additional rules that apply to the use of labels:
0 They must not appear in the function header.
You cannot assign values to them.
0 They can be up to 77 characters in length.
They cannot be used on comments.
0 When duplicate labels or labels that duplicate a local name are used, the first
use of the label or name is the accepted use.
If the branch is to zero (-to) or any statement number not in the function, the
function is exited when the branch statement is executed. If the value to the right
of the + is a vector (for example, +LI,L2,L3), the branch is determined by the
vector's first element. If the vector is an empty vector (there are no elements), the
branch is not executed, and the normal sequence of statement execution continues.
For example, the conditional branch +(I ?N)/START is evaluated as follows:
1. First, the condition (I?N) is evaluated; the result is 1 if the condition is
true and 0 if the condition is false.
2. The result of step 1 is then used as the left argument for the compress
(A/B) function:
a. If the result of step 1 was 1, START is selected from the right argument
and a branch to the statement labeled START is taken.
b. If the result of step 1 was 0, nothing is selected from the right argument
(an empty vector is the result) and the sequence of execution falls through
to the next statement.
Following are three examples of defining and using a function to determine the
sum of the first N
integers. Each function uses a different method of branching.
Remember, the expression to the right of the + is evaluated and the result deter.
mines to what statement the branch is taken:
SlJM :I. 5
1.5
Several forms of the branch instruction are shown in the following table:
Branch Instruction Result
Branches to a statement labeled LABEL
Exits function
Branches to LABEL or exit function
}
Branches to LABEL or falls through
c
c
c.:
Note: Branching will also work if a specific statement number is specified to the
right of the +. For example, +3 means branch to statement 3; or +l+-3xA means
I is assigned the value of 3 times the value of A, and the value of I is then used as
the branch to statement number. However, these forms of branching (using
statement numbers instead of labels) can cause problems if the function is edited
and the statements are renumbered.
Local and Global Names
A local name is the name of a variable or user-defined function that is used only
within a particular user-defined function. A global name is the name of a variable
or user-defined function that can be used within a user-defined function and can
also be
used outside of it. An example of the use of a local variable name would
be the name of a counter used in a user-defined function (which is not required
for any use outside the function).
139
Previous Page Next Page