next up previous contents
Next: The elif Command Up: Decisions Previous: The if-then-fi Command

Nesting if-then-fi Commands

We can nest if-then-fi commands inside of if-then-fi commands when there are more than two possible outcomes.
> x := 5:                    #  compare if x<y or x>y or x=y
> y := 7:
> if (x < y) then
>   lprint(x, ' is less than ', y);
> else
>   if (x > y) then
>     lprint(x, ' is greater than ', y);
>   else
>     lprint(x, ' is equal to ', y);
>   fi;
> fi:
5  is less than  7
Here the second if-then-fi command is contained within the else case of the outer if-then-fi. It is evaluated only if x $\geq$ y.



Gaston Gonnet
1998-09-15