Short-circuit evaluation
The test of the IF expression may be "short-circuited":
- if the IF expression consists of a logical OR of 2 expressions and the
first of these expressions is "true", then the second expression
will not be evaluated and the code will execute the THEN clause
- similarly
if the IF expression consists of a logical AND of 2 expressions and the
first of these expressions is "false", then the second expression
will not be evaluated and the code will execute the ELSE clause
The code will short-circuit only some expressions however, namely those
which are:
- a comparison expression
- a BIT(1) literal
- a NONVARYING BIT(1) variable
- an ENTRY reference that returns NONVARYING BIT(1)
- a SUBSTR built-in function reference with 3 arguments the
last of which is a REAL FIXED literal equal to 1
- an ALL or ANY built-in function reference with an an argument
that is either
a comparison operator applied to 2 arrays or
simply a variable that is an array of NONVARYING BIT(1)
- one of the following other built-in functions
- Checkstg
- Endfile
- Fileopen
- Isfinite
- Isinf
- Ismain
- Isnan
- Isnormal
- Iszero
- Omitted
- Present
- Unallocated
- Valid
- Validdate
Naturally, an expression formed (possibly recursively) from the above
and the NOT prefix operator and the AND or OR infix operators will
also be short-circuited.
So, for example, given the following declares
dcl A bit(1);
dcl B bit(1);
dcl C bit(2);
dcl D bit(2);
dcl P pointer;
dcl BX based fixed bin(31);
Then the following IF statements would all be short-circuited:
if A | B then
if P = sysnull() | P->BX = 0 then
if C = ''b & D = ''b then
if A | (substr(C,1,1) & substr(D,2,1)) then
But the following IF statements would not be short-circuited:
if C | D then
if C & D then
|
This information center is powered by Eclipse technology. (http://www.eclipse.org)