<A NAME=IF>
<TITLE>IF</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>
<B>IF</B> _ _ _ _ _ _ _ _ _ _ _ _ <B>command</B><P>
<P>
The <em>if</em> command is a conditional statement that executes a statement
if a condition is true, and optionally another statement if it is not.
<P> <H3>
syntax: </H3>
<P>
<P>
<em>if</em><condition> <em>then</em> <statement>
_ _ _ option(<em>else</em> <statement>)
<P>
<P>
<P>
<condition> must be a logical or comparison operator that evaluates to
a
<A HREF=r37_0109.html>boolean value</A>.
<statement> must be a single REDUCE statement or a
<A HREF=r37_0038.html>group</A> (<em><<</em>...<em>>></em>) or
<A HREF=r37_0041.html>block</A> (<em>begin</em>...<em>end</em>) statement.
<P>
<P>
<P> <H3>
examples: </H3>
<P><PRE><TT>
if x = 5 then a := b+c else a := d+f;
D + F
x := 9;
X := 9
if numberp x and x<20 then y := sqrt(x) else write "illegal";
3
clear x;
if numberp x and x<20 then y := sqrt(x) else write "illegal";
illegal
x := 12;
X := 12
a := if x < 5 then 100 else 150;
A := 150
b := u**(if x < 10 then 2);
B := 1
bb := u**(if x > 10 then 2);
2
BB := U
</TT></PRE><P>An <em>if</em> statement may be used inside an assignment statemen
t and sets
its value depending on the conditions, or used anywhere else an
expression would be valid, as shown in the last example. If there is no
<em>else</em> clause, the value is 0 if a number is expected, and nothing
otherwise.
<P>
<P>
The <em>else</em> clause may be left out if no action is to be taken if the
condition is false.
<P>
<P>
The condition may be a compound conditional statement using
<A HREF=r37_0039.html>and</A> or
<A HREF=r37_0054.html>or</A>. If a non-conditional statement, such as a constant
, is used by
accident, it is assumed to have value true.
<P>
<P>
Be sure to use
<A HREF=r37_0038.html>group</A> or
<A HREF=r37_0041.html>block</A> statements after
<em>then</em> or <em>else</em>.
<P>
<P>
The <em>if</em> operator is right associative. The following constructions are
examples:
<P>
<P>
_ _ _ (1)
<P> <H3>
syntax: </H3>
<P>
<P>
<em>if</em><condition> <em>then</em> <em>if</em> <condition> <em>the
n</em>
<action> <em>else</em> <action>
<P>
<P>
<P>
which is equivalent to
<P> <H3>
syntax: </H3>
<P>
<P>
<em>if</em><condition> <em>then</em> (<em>if</em> <condition>
<em>then</em> <action> <em>else</em> <action>);
<P>
<P>
<P>
_ _ _ (2)
<P> <H3>
syntax: </H3>
<P>
<P>
<em>if</em><condition> <em>then</em> <action> <em>else if</em>
<condition> <em>then</em> <action> <em>else</em> <action>
<P>
<P>
<P>
which is equivalent to
<P> <H3>
syntax: </H3>
<P>
<P>
<em>if</em><condition> <em>then</em> <action> <em>else</em>
<P>
<P>
(<em>if</em> <condition> <em>then</em> <action>
<em>else</em> <action>).
<P>
<P>
<P>
<P>
<P>
<P>