up previous next

If

Syntax

If B Then C EndIf
If B_1 Then C_1 Else C_2 EndIf
If B_1 Then C_1 Elsif B_2 Then C_2 Elsif ... EndIf
If B_1 Then C_1 Elsif B_2 Then C_2 Elsif ... Else C_r EndIf

D If B

where the B's are boolean expressions, the C's are command
sequences, and D is a single command.
    

Summary

conditional statement

Description

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

In the last form, the single command D is performed if B evaluates to TRUE. NOTE: the use of this form is discouraged. It will probably disappear from future versions of CoCoA.

For a conditional expression, assignable to a variable, see Cond.

example

    
Define Sign(A)
  If A > 0 Then Return 1
  Elsif A = 0 Then Return 0
  Else Return -1
  EndIf
End;

Sign(3);
1
-------------------------------
        
    

See Also