next up previous contents
Next: Nesting if-then-fi Commands Up: Decisions Previous: Decisions

The if-then-fi Command

No programming language is useful unless it allows programs to make decisions. The typical construct used for ``controlling the flow of execution'' is the if-then-fi command:

> x := 5:
> if (x=5) then
>   print('I\''m a number five');
> else
>   print('I\''m not a number five');
> fi:
I'm a number five
The first statement x:=5 assigns the value 5to the variable name x. The boolean expression (x = 5) found in the second line is called the conditional of the if-then-fi command. In the example here, the variable x contains the integer 5, so the boolean conditional is true and the print command is executed. If the variable had not been assigned 5, then the boolean conditional would evaluate to false and the program would perform the second print command located in the else case.

The else command can be omitted from an if-then-fi command.

Gaston Gonnet