Making Decisions And Solving Problems; If-Then,For-Next - Atari 65XE Owner's Manual

Hide thumbs Also See for 65XE:
Table of Contents

Advertisement

Making Decisions
and Solving Problems:
The IF-THEN and FOR-NEXT commands enable you to write programs
that mimic the way humans approach a decision or a problem.
Especially useful for games and logic puzzles, the commands let you,
the programmer, make the choices for the computer.
IF-THEN COMMANDS
To practice the IF-THEN statement, type in the following program:
NEW
1 REM *** BRNPROBE . QZ ***
5 PRINT "
"
10 DIM RAIN$ (3)
20 PRINT:PRINT "YES OR NO, IF IT HERE RAINING OUTSIDE,
WOULD YOU GO OUT WITH AN U M B R E L L A " ;
30 INPUT RAIN$
40 IF RAIN$ = "YES" THEN PRINT "YOU HAVE A FORMIDABLE IQ . "
50 IF RAIN$="NO" THEN PRINT "YOU A R E A BORN RISK TAKER."
The Brainprobe Quiz evaluates your answer. In line 40, if the answer
stored in the string variable RAIN$ is yes, the computer prints the IQ
message. If the answer is not yes, the computer reads the next line,
line 50, and evaluates the string variable RAIN$ again. If the answer is
NO, the computer prints the risk-taker message. However, if you
answer neither yes nor no, the program just ends. The program has no
instructions for responding to an indefinite answer. Try it out.
One way to encourage an expected reply is to create an infinite loop.
Insert the additional line below:
60 GOTO 20
Evaluating with IF-THEN
Another way to encourage a correct answer is to provide hints. The
following program uses numeric variables to elicit a correct response:
NEW
1 REM *** NUMBER . QZ ***
5 PRINT "
"
10 SECRETNUM=INT(RND(0)*10)+1
20 PRINT:PRINT "GUESS A SECRET NUMBER BETWEEN 1 AND 10 ."

IF-THEN,FOR-NEXT

55

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 65XE and is the answer not in the manual?

Table of Contents

Save PDF