The -if- and -else- Commands
Suppose you want to do one set of statements if x is greater than y, and a different set of statements. One way to do this, as we have seen, is to put the two sets of statements in two different units and write “do x>y, unita, unitb”. Another way to perform these operations is to use -if- and -else- commands:
The statements between the -if- and -else- commands are performed only if x is greater than y, and the statements between the -else- and -endifcommands are performed otherwise. The tag of the -if- command must be a logical expression (one that has values -1 or 0). The tag of the -elsecommand must be blank. The -endif- command identifies the end of the sequence.
Note that the statements bracketed by -if-, -else-, and -endif- must be indented, with an initial period identifying them as indented statements. (It is possible that the details of this indenting format may change. Consult on-line PLATO aids for up-to-date information.)
When do you use a conditional -do-, and when do you use -if- and -else-? This depends mainly on the number of statements involved. If there are few statements to be performed, -if- and -else- is probably more readable. But, if “unita” and “unitb” are long subroutines, the conditional -do- is the more convenient form.
There doesn't have to be an -else-:
This will do the -talc- and -draw- only if x is greater than y.
There is also an -elseif- for specifying an additional condition:
The text “Two levels!” will appear on the screen if (a=b $or$ b>3) and if (count<8).