•
All these are binary decisions. The
first
two examples are simple either something
happens or
it
does
not.
The third
is
a general binary decision with two distinct possible
courses of acfion, both of which must be defined.
You
can omit THEN
in
the long forms
if
you
wish.
In
the short form
you
can substitute
:
for
THEN.
Consider a more complex example
In
which
it
seems natural
to
nest binary decIsions. EXAMPLE
ThiS
type of nesting can be confusing and
you
should only
do
It
If
it
seems the most
natural thing
to
do.
Careful attention
to
layout particularly indenting,
is
espeCially
Important.
Analyse a piece
of
text
to
count the number of
vowels,
consonants and other characters.
Ignore spaces. For simplicity the
text
is
all
upper
case.
"COMPUTER HISTORY
WAS
MADE
IN
1984" Data
ProgramStructure
•
•
Read
in
the data
FOR each character:
IF letter THEN
IF
vowel
increase vowel count
ELSE
increase
consonant
count
END IF
ELSE
IF not space THEN increase other count
END IF
END FOR
PRINT results
100
REMark
Character
Counts
110
RESTORE
290
120
READ
text$
130
LET
voweLs
=
0:
cons
=0 :
others
=0
140
FOR
nurn
=1
TO
LEN
(text
[)
150
LET
ch$
=
text$(nurn)
160
IF
ch$
>=
"A"
AND
ch$
<=
liZ"
170
IF
ch$
INSTR
"AEIOU"
180
LET
voweLs
= voweL +
190
ELSE
200
LET
cons
=
cons
+ 1
210
END
IF
220
ELSE
230
IF
ch$
<>
..
II
THEN
others::::
others
+ 1
240
END
IF
250
END
FOR
nurn
260
PRINT
"Vowel
count
is"
!
vowels
270
PRINT
"Consonent
count
i 5
11
!
cons
280
PRINT
"Other
count
;s"
!
others
290
DATA
"COMPUTER HISTORY
WAS
MADE
IN
1984"
Vowel
count
is
9
Consonant
count
is
15
Other
count
is
4
Where there are three or more possible actions and none
is
dependant on a previous
choice the natural structure
to
use
is
SElect
which enables selection from any number
of possibilities.
A magic snake grows without limit by adding a section
to
ItS
front.
Each section may
be
up
to
twenty units long and may be a new colour or
it
may remain the
same.
Each
new section must grow
in
one of the directions North, South
East
or
West.
The snake
starts from the centre of the window.
12/84
Design
Program
Output
MULTIPLE
DECISIONS
-
SELect
EXAMPLE
83