English
Language : 

NSB8 Datasheet, PDF (104/158 Pages) List of Unclassifed Manufacturers – BASIC interpreter for Z80 family
grifo®
ITALIAN TECHNOLOGY
In example #6, the loop controlled by J is the body of the loop controlled by I. The statements from
20 to 40 will be repeated 10 times (as I goes from 0 to 9), but these statements in themselves comprise
a loop which will also repeat 10 times. The net effect is that, for every change in J, line 30 will have
been executed once, but for every chenge in I it will have been repeat 10 times. As a result of example
#6, line 30, the body of the inner loop, will be repeated 10 times 10, or 100, times. The following is
a sample of the output generated:
01
02
03
:
: etc.
:
97
98
99
FOR loops may be nested to any arbitrary depth. However, there must always be a NEXT to match
each FOR. Also, a different variable must be used to control each nested loop.
THE OPTIONAL CONTROL VARIABLE IN NEXT
The control variable of a loop may be optionally be specified in the next statement which ends that
loop.
Example #7
10 FOR I=1 TO 10
20 FOR J=1 TO 10
30 PRINT I, J
40 NEXT I
50 NEXT J
Inclusion of the control variable in the NEXT statement is useful on clarifying the program text
(determining which NEXT goes with which FOR). If the optional control variable is specified on
the NEXT statement, BASIC will perform a syntax check during program execution and will cause
a program error of the control variable specified in the NEXT is not the same as that specified in the
matching FOR.
USING EXIT
A FOR loop may be terminated before all the specified repetitions have been performaded if an EXIT
statement is executed. EXIT is used to transfer program control to line outside the loop, that is before
the loop’s FOR statement or after its NEXT. EXIT is like a GOTO, in that it causes a transfer of
control to the specified line number, but it also tells BASIC to end the current FOR loop: no more
repetitions will be necessary. BASIC uses memory storage to remember information about the
FOR loop while it is repeating. EXIT tells BASIC to release the memory used by the current loop.
If it is not used to jump out of a FOR loop, then subsequent loops may not execute correctly.
Page 92
NSB8
Rel. 5.10