next up previous contents
Next: Looping Around Up: Decisions Previous: The elif Command

The If Command

Another if-then-fi variant that offers some convenience from time to time is the If(cond, exprtrue, exprfalse). This function returns the result of evaluating exprtrue if the boolean conditional cond is true or it returns the result of evaluating exprfalse if cond is false.

> x := 101:                            # x is just some number
> round_up := If( mod(x, 2)=0 , x/2, (x+1)/2 );
round_up := 51
> x := 44:
> round_up := If( mod(x, 2)=0 , x/2, (x+1)/2 );
round_up := 22



Gaston Gonnet
1998-09-15