User guide
24 CHAPTER 2. THE BCPL LANGUAGE
where E denotes an expression and C
1
and C
2
denote commands. The symbols
DO and THEN may be omitted whenever they are followed by a command keyword.
To execute a conditional command, the expression E is evaluated in a Boolean
context. If it yields a non zero value and C
1
is present then C
1
is executed. If it
yields zero and C
2
is present, C
2
is executed.
2.3.4 Repetitive Commands
The syntax of the repet it i ve commands is as follows:
WHILE E DO C
UNTIL E DO C
C REPEAT
C REPEATWHILE E
C REPEATUNTIL E
FOR N = E
1
TO E
2
DO C
FOR N = E
1
TO E
2
BY K DO C
The symbol DO may be omitted whenever it is followed by a command key-
word. The WHILE command repeatedly executes the command C as long as E
is non-zero. The UNTIL command executes C until E is zero. The REPEAT com-
mand executes C indefinitely. The REPEATWHILE and REPEATUNTIL commands
first execute C then behave like WHILE E DO C or UNTIL E DO C, respect ively.
The FOR command first initialises its control variable (N ) to the value of
E
1
, and evaluates the end limit E
2
. Until N moves beyond the end limit, the
command C is executed and N increment by the step length given by K which
must be a manifest constant expressi on (see Section 2.2.10). If BY K is omitted
BY 1 is assumed. A FOR comm and starts a new dynamic scope and the control
variable N is allocated a location within this new scope, as are all other dynamic
variables and vectors wi t h i n the FOR command.
2.3.5 SWITCHON command
A SWITCHON command has the following for m :
SWITCHON E INTO { C
1 ;...; C n }
where the commands C
1
to C
n
may have labels of the form DEFAULT: or CASE K.
E is evaluated and then a jump is made to the pl ac e in the bod y labelled by
the matching CASE label. If no CASE label with the required value exists, then
control goes to the DEFAULT label if it exists, otherwise execution continues from
just after the switch.