If Then - AMSTRAD CPC464 User Manual

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

The main cursor has moved but the copy cursor stayed where it was. Now press the [COPY] key
until the whole of line 10 is printed. Press [ENTER] and this new line 10 will be stored in the
memory. The copy cursor disappears and the main cursor positions itself under the new line 10. To
correct the second mistake, hold down [SHIFT] and press cursor up key [ t ] until the copy cursor
appears over the very beginning of line 30.
Press [COPY] until the copy cursor is positioned over the quotations next to s a y . Now press the
space bar once. A space will be inserted on the bottom line. Hold down the [COPY] key until the
whole of line 30 is printed. Then press [ENTER]. You can now list the program to check that it is
corrected in the memory by typ-ing:
list [ENTER].
Now reset the computer by pressing [CTRL] [SHIFT] and [ESC] keys.

IF THEN

We will now extend the previous program with the use of the if and then comands.
Type in the following : Notice that we have added two symbols. < means less than and is next to the
M key, > means greater than and is next to the < (less than) key.
5 c l s [ E N T E R ]
1 0 i n p u t " w h a t i s y o u r n a m e " ; a $ [ E N T E R ]
2 0 i n p u t " w h a t i s y o u r a g e " ; a g e [ E N T E R ]
3 0 i f a g e < 1 3 t h e n 6 0 [ E N T E R ]
4 0 i f a g e < 2 0 t h e n 7 0 [ E N T E R ]
5 0 i f a g e > 1 9 t h e n 8 0 [ E N T E R ]
6 0 p r i n t " S o " a $ " Y o u a r e n o t q u i t e a t e e n a g e r
a t " a g e " y e a r s o l d " : e n d [ E N T E R ]
7 0 p r i n t " S o " a $ " y o u a r e a t e e n a g e r a t "
a g e " y e a r s o l d " :e n d [ E N T E R ]
8 0 p r i n t " O h w e l l " ; a $ " Y o u a r e n o l o n g e r
a t e e n a g e r a t " a g e " y e a r s o l d " [ E N T E R ]
To check this program is correct, type:
list
[ENTER]
Now type in :
run
[ENTER]
Now answer the questions prompted by the computer and see what happens.
You can now see what effect the if and then commands have in a program. We have also added the
word end at the end of line 60 and 70. The keyword end is used literally to end the running of a
program. If end wasn' t there in line 60, the program would continue to run, and carry out lines 70
and 80.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents