up previous next
 Cond

conditional expression
 Syntax
 ``` Cond B_1 Then E_1 EndCond Cond B_1 Then E_1 Elsif B_2 Then E_2 Elsif ... EndCond Cond B_1 Then E_1 Elsif B_2 Then E_2 Elsif ... Else E_r EndCond Cond(B_1, E_1, B_2, E_2,...,E_r) where the B_i's are boolean expressions and the E_i's are expressions. ```

 Description
If B_n is the first in the sequence of B_i's to evaluate to TRUE, then E_n is returned. If none of the B_i's evaluates to TRUE, then Null is returned. The construct, Elsif B Then E can be repeated any number of times. Note: be careful not to type Elseif by mistake (it has an extraneous e).

The difference between Cond and If is that Cond is an expression which may be assigned to a variable; each of the E_i's is an expression, not a general sequence of commands (as their analogues in If might be).

 Example
 ``` Define Sign(A) Return Cond A>0 Then 1 Elsif A=0 Then 0 Else -1 EndCond; EndDefine; Sign(3); 1 ------------------------------- Define PrintSign(A) Return Cond(A>0,"positive", A=0,"zero","negative"); EndDefine; PrintSign(3); positive ------------------------------- ```