You can make a computer compare pieces of
information and then do different things according to
the results. To do this you use the commands IF and
THEN. You can find out how IF and THEN work in the
program below.
NEW
10 CLS
20 PRINT "TYPE IN TWO NUMBERS"
30 INPUT A
40 INPUT Z
50 IF A=Z THEN PRINT "EQUAL"
60 IF A<>Z THEN PRINT "NOT EQUAL"
RUN
In this program the IF and THEN commands
make the computer compare the numbers
stored in the variables A and Z. If the
numbers are the same the computer displays
the message "EQUAL". If the numbers are
different, the message is "NOT EQUAL".
Comparing words
You can also use IF and THEN to
make the computer compare words.
Try running the program below.
The IF and THEN commands make
the computer compare the
names stored in S$ and
N$, to see if they are the
same or not.
NEW
10 CLS
20 S$="SLIMY SID"
30 PRINT "WHAT'S YOUR NAME?"
40 INPUT N$
50 IF N$<>S$ THEN PRINT "I CAN'T STAND MONSTERS CALLED "; N$
60 IF N$=S$ THEN PRINT "HELLO ";S$;" NICE TO MEET YOU"
RUN
Age program
When you type in this program, put your own age in line 20. Then let a friend run the
program. The computer will work out whether your friend is older, younger or the same age as you.
NEW
10 CLS
20 A=11
30 PRINT "I AM";A;" YEARS OLD"
40 PRINT "HOW OLD ARE YOU?"
50 INPUT B
60 IF A=B THEN PRINT "WE'RE THE SAME AGE!"
70 IF A>B THEN PRINT "I'M OLDER THAN YOU"
80 IF A<B THEN PRINT "I'M YOUNGER THAN YOU"
RUN