AMSTRAD cpc 6128 User Instruction page 42

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

i f 1
+
1
=
2 the n pr i n t "c
0
r re et" [RETURN]
.... the computer will test for the specified condition, and then take action accordingly.
The keyword E LSE can be used to inform the 1FT HEN command as to what
alternative action the computer should take if the tested condition is false, for
example:
i f 1
+
1
=
0 the n p r i n t "c
0
r r e et" e Lse p r i n t " w r
0
n g" [RETURN]
We will now extend the previous program with the use of the i f and the n
commands.
Type in the following: Notice that we have added two symbols.
<
means less than, and
is next to the M key.
>
means greaterthan,and is next to the
<
(less than) key.
5
c
L
s [RETURN]
10 input "what is your name";a$ [RETURN]
20 i n put " w hat i s you rag e " ; age [RETURN]
30 i fag e
<
1 3 the n 60 [RETURN]
40 i fag e
<
20 the n 70 [RETURN]
50 i fag e
>
1 9 the n 80 [RETURN]
60 print "So ";a$;", you are not quite a
tee nag era t " ; age; " yea r soL d" : end [RETURN]
70 print "So ";a$;", you are a teenager
at" ; age; "yea r soL d" : end [RETURN]
80 print "Oh weLL ";a$;", you are no
L
0
n
~
e
r_~
t_ee_
n'!~L~r ~t";_ ~g_e
; "yea r!i
Q
1 d" [RETURN]
To check this program is correct, type:
Lis t [RETURN]
Nowtypein:
run [RETURN]
Now answer the questions prompted by the computer and see what happens.
You can now see what effect the I F and THE N commands have in a program. We
have also added the wcrd END at the end of lines 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.
Foundation Course
Chapter 1 Page 29

Advertisement

Table of Contents
loading

Table of Contents

Save PDF