INTRODUCTION
This section introduces you to some powerful BASIC commands
and statements that you probably have not seen before, even if
you are an experienced BASIC programmer. If you are familiar
with programming in BASIC, you have probably encountered
many situations in which you could have used these commands
and statements. This section explains the concepts behind each
command and gives examples of how to use each command in a
program. (A complete list and an explanation of these commands
and statements may be found in Chapter V, BASIC 7.0
Encyclopaedia.) This section also describes how to use the
special keys that are available to you in C128 mode.
ADVANCED LOOPING
DO/LOOP statement
The DO/LOOP statement provides more sophisticated ways to
create a loop than do the GOTO, GOSUB or FOR/NEXT
statements. The DO/LOOP statement combination brings to the
BASIC language a very powerful and versatile technique normally
available only in structured programming languages. We discuss
just a few possible uses of DO/LOOP in this explanation.
If you want to create an infinite loop, you start with a DO
statement, then enter the line or lines that specify the action you
want the computer to perform. Then end with a LOOP statement
like this:
100 DO
110 PRINT “REPETITION”
120 LOOP
Press the RUN/STOP key to stop the program.
The directions following the DO statement are carried out until
the program reaches the LOOP statement (line 120); control is
then transferred back to the DO statement, (line 100). Thus any
statements in between DO and LOOP are performed indefinitely.
UNTIL
Another useful technique is to combine the DO/LOOP with the
UNTIL statement. The UNTIL statement sets up a condition that
5-3