CoCoA:If

From ApCoCoAWiki
Revision as of 10:02, 24 October 2007 by XMLBot (talk | contribs) (pushing XML rev. 1.46, again)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

If

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

<ttref>Cond</ttref>.

Example

  Define Sign(A)
    If A &gt; 0 Then Return 1
    Elsif A = 0 Then Return 0
    Else Return -1
    EndIf
  EndDefine;

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

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.

Cond

   <type>programming</type>
   <type>branching</type>