Next: , Previous: , Up: Operators   [Contents][Index]

#### 6.3.5 Binary Logical Conditional Operators

Binary conditional operators are defined for integer scalars (Scalars). They are somewhat similar to the corresponding binary logical operators (Binary Logic) but suppress evaluation of the second operand if the first operand is sufficient to determine the value of the whole expression.

The available conditional operators are:

Conditional And

`x ANDIF y` yields 0 if `x` is equal to zero (and then `y` is not evaluated), and yields 1 if both `x` and `y` are unequal to zero. These results are the same as returned by ```x NE 0 AND y NE 0``` (Binary Relationals), except that `y` is not evaluated if `x` is equal to zero, for then the value of the whole expression is zero regardless of the value of `y`.

Conditional Or

`x ORIF y` yields 1 if `x` is unequal to zero (and then `y` is not evaluated), and yields 0 if both `x` and `y` are equal to zero. These results are the same as returned by ```x NE 0 OR y NE 0```, except that `y` is not evaluated if `x` is unequal to zero, for then the value of the whole expression is zero regardless of the value of `y`.

Conditional operators provide short-hand notation for certain IF statements:

```IF x THEN
IF y THEN statement
```

can be rewritten

```IF x ANDIF y THEN statement
```

and

```IF `x` THEN
statement
ELSE IF `y` THEN
statement
```

can be rewritten

```IF `x` ORIF `y` THEN statement
```

Such `if` statements (and therefore the use of conditional operators) is useful if `y` is expensive to calculate or if it may lead to an error when `y` is nonzero. For example, in the `if` statement

```IF z EQ 0 ORIF 123/z GT 5 THEN T,'OK'
```

the `orif` operator prevents division by zero in `123/z` if `z` is equal to zero, and in the `if` statement

```IF ok EQ 17 ANDIF EXPENSIVE(x + 2) THEN T,'OK'
```

the `andif` operator prevents evaluation of `EXPENSIVE(x + 2)` if `ok` is not equal to 17.

Next: , Previous: , Up: Operators   [Contents][Index]