HELP IF Steven Hardy Jan 1978
Revised: Adrian Howard Mar 1992
-if- is the first word of a conditional expression, for example:
if tough(steak) then
fry(steak)
else
grill(steak)
endif
When this statement is executed, the POP-11 system first executes the
condition (i.e. "tough(steak)"); if this evaluates to -false- then
"grill(steak)" is executed, otherwise "fry(steak)" is executed. The full
syntax of allowable conditional commands is quite complex. An -if-
statement has the form:
if <CONDITION>
then <CONSEQUENT>
elseif <CONDITION>
then <CONSEQUENT>
...
[any number of additional -elseif-...-then-.... clauses]
...
else
<CONSEQUENT>
endif
The "else <CONSEQUENT>" can be omitted if desired. The "elseif
<CONDITION> then <CONSEQUENT>" can be either omitted or repeated as many
times as required. A <CONDITION> is any expression, and a <CONSEQUENT>
is any sequence of POP-11 statements.
The condition should, when executed, produce a result. If the result is
-false-, then the corresponding consequent is ignored, and the program
moves on to the next -elseif-, or if there isn't one, to the -else-
clause. If there is no -elseif- or -else-, then the program moves on to
the instruction following the -endif-.
If the result of executing a condition is anything other than -false-,
then it is treated as if it were -true-, and the corresponding
consequent is executed, e.g.
if 3 then "three" endif =>
** three
IF statements can be nested inside one another, i.e. a <CONDITION> or a
<CONSEQUENT> of an -if- statement may itself contain -if- statements.
For example:
if isnumber(n) then
if n > 0 then
'positive'=>
else
'less than or equal to zero'=>
endif;
endif;
It is permissible, but unusual, for a <CONSEQUENT> to contain no code at
all, for example:
define prlist(list);
lvars list;
if list == [] then
else
hd(list) =>
prlist(tl(list));
endif
enddefine
It is clearer to use *UNLESS in this case, i.e.:
define prlist(list);
lvars list;
unless list == [] then
hd(list)=>
prlist(tl(list));
endunless;
enddefine;
The expression
unless <CONDITION> then <CONSEQUENT>
is equivalent to:
if not(<CONDITION>) then <CONSEQUENT>
See *UNLESS and *NOT for more details. There is also an -elseunless-
branch which is used in the same way as -elseif-. The expression
... elseunless <CONDITION> ...
is the same as doing
... elseif not(<CONDITION>) ...
If a conditional statement starts with -if- it must end with -endif-. If
it starts with -unless- it must end with -endunless-. Either form may
include -elseif-, -elseunless-, or -else- clauses.
For further information see:
*ELSEIF *ELSEUNLESS *UNLESS
*BOOLEAN --- Boolean values in POP-11.
*CONDITIONALS --- Summary of conditional statements in POP-11.
*CONTROL --- An overview of control facilities in POP-11.
REF *SYNTAX *POPSYNTAX
Summary of POP-11 syntax
--- C.all/help/if
--- Copyright University of Sussex 1992. All rights reserved. ----------Author: Steven Hardy Jan 1978