Sharp MZ-700 Series Owner's Manual page 49

Personal computer
Hide thumbs Also See for MZ-700 Series:
Table of Contents

Advertisement

2.3.6 Loop and branch instructions
2. 3. 6. 1 FOR ~ NEXT
Format
FOR cv = iv TO fv < STEP sv >
(abbreviated format: F. ~ N.)
Function
NEXT < cv >
cv . . . . Control variable; a numeric variable or array element,
iv . . . . Initial value; a numeric expression,
fv . . . . Final value; a numeric expression.
sv . . . . Increment, or step value; a numeric expression (if omitted, 1 is assumed).
This statement repeats the instructions between FOR and NEXT a certain number
of times.
1 0
A = 0
2 0
F O R
N = 0
T O
1 0
S T E P
2
3 0
A = A + 1
4 0
P R I N T
" N = " ; N ,
5 0
P R I N T
" A = "
; A
6 0
N E X T
N
(1) In the program above, 0 is assigned to N as the initial value.
(2) Next, lines 20 through 50 are executed and the values of variables A and N
displayed.
(3) In line 60, the value of N is increased by 2, after which the BASIC interpreter
checks to see whether N is greater than 10, the final value. If not, lines following
line 20 are repeated.
When the value of N exceeds 10, execution leaves the loop and subsequent instruc-
tions (on lines following line 60) are executed. The program above repeats the loop
6 times.
If < STEP sv > is omitted from the statement specification, the value of N is increas-
ed by 1 each time the loop is repeated. In the case of the program above, omitting
< STEP sv > in this manner would result in 11 repetitions of the loop.
i
j
47

Advertisement

Table of Contents
loading

Table of Contents