Making Decisions
and Solving Problems:
IF-THEN,FOR-NEXT
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 *** B R N P R O B E . QZ ***
5 PRINT " "
10 DIM R A I N $ (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 R A I N $
40 IF RAIN$ = "YES" THEN PRINT "YOU HAVE A F O R M I D A B L E IQ . "
50 IF RAIN$="NO" THEN PRINT "YOU A R E A B O R N 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 *** N U M B E R . QZ ***
5 PRINT " "
10 SECRETNUM=INT(RND(0)*10)+1
20 PRINT:PRINT "GUESS A SECRET N U M B E R BETWEEN 1 A N D 10 ."
55
Summary of Contents for 65XE
Page 1: ...ATARI 65XE PERSONAL COMPUTER OWNER S MANUAL TM...
Page 3: ...ATARI 65XE PERSONAL COMPUTER TM...
Page 6: ...Part 1 GettingStarted 1...
Page 9: ...4...
Page 23: ...18...
Page 25: ...20...
Page 32: ...Part 2 Programming withATARI BASIC 27...
Page 33: ...28...
Page 59: ...54...
Page 69: ...64...
Page 82: ...Part3 Appendices 77...
Page 83: ...78...
Page 97: ...92...
Page 105: ...100...
Page 125: ...120...
Page 126: ...121 Index...
Page 127: ...122...
Page 134: ...ATARI 1987 Atari Corp All Rights Reserved Printed in Taiwan C072018 001 REV B K l 2 1987...
Page 135: ......