directs the loop. The loop will run continually unless the condition
for UNTIL happens.
100 DO: INPUT “DO YOU LIKE YOUR COMPUTER”;A$
110 LOOP UNTIL A$=“YES”
120 PRINT “THANK YOU”
The DO/LOOP statement is often used to repeat an entire
routine indefinitely in the body of a program, as in the following:
10 PRINT “PROGRAM CONTINUES UNTIL YOU TYPE
QUIT’”
20 DO UNTIL A$=“QUIT”
30 INPUT “DEGREES FAHRENHEIT”;F
40 C=(5/9)*(F-32)
50 PRINT F;“ DEGREES FAHRENHEIT EQUALS “;C; “
DEGREES CELSIUS”
60 INPUT “AGAIN OR QUIT”;A$
70 LOOP
80 END
Another use of DO/LOOP is as a counter, where the UNTIL
statement is used to specify a certain number of repetitions.
10 N=2*2
20 PRINT“TWO DOUBLED EQUALS”; N
30 DO UNTIL X=25
40 X=X+1
50 N=N*2
60 PRINT“DOUBLED”;X+1;“TIMES...”;N
70 LOOP
80 END
Notice that if you leave the counter statement out (the UNTIL
X=25 part in line 30), the number is doubled indefinitely until an
OVERFLOW error occurs.
WHILE
The WHILE statement works in a similar way to UNTIL, but the
loop is repeated only while the condition is in effect, such as in
this reworking of the last brief program:
100 DO: INPUT “DO YOU LIKE YOUR COMPUTER”;A$
110 LOOP WHILE A$<> “YES”
120 PRINT “THANK YOU”
5-4