AII 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 action, 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.
EXAMPLE
Consider a more complex example in which it seems natural to nest binary decisions. 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.
Data:
"COMPUTER HISTORY WAS MADE IN 1984"
Design:
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 num = 1 TO LEN(text$)
150 LET ch$ = text$(num)
160 IF ch$ >= "A" AND ch$ <= 'Z'
170 IF ch$ INSTR "AEIOU"
180 LET vowels = vowels + 1
190 ELSE
200 LET cons = cons + 1
210 END IF
220 ELSE
230 IF ch$ <> " " THEN others = others + 1
240 END IF
250 END FOR num
260 PRINT "Vowel count is" ! vowels
270 PRINT "Consonant count is" ! cons
280 PRINT "Other count is" ! others
290 DATA "COMPUTER HISTORY WAS MADE IN 1984"
Output
Vowel count is 9
Consonant count is 15
Other count is 4