EasyManua.ls Logo

Sharp MZ-700 - Page 49

Sharp MZ-700
213 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
2.3.6 Loop and branch instructions
2. 3. 6. 1
FOR~
NEXT . .
...........
..
...........
.
..
......
(abbreviated
format:
F.~
N.)
I
Format
I FOR cv =
iv
TO
fv
< STEP sv >
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.
10
A=
0
20
FOR
N=0
TO
1 0
STEP
2
30
A=A+1
4 0
PRINT
11
N==
11
;
N.
50
PRINT
11
A==
11
;A
60
NE XT 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
.
FOR
c-
--
-
-------~
l N
=O
[
I I
L
--
------
-l
Loop control
variable
.-
-----
-
--
----
-
-----
-----
-----r
I I
[
TO
1 0
STEP
2 :
t_
___
_
____
_
--------
--
---.
I
Final value
of
N
I
I
I
I
I
I
I
Increment
for N (step)
Initial value
of
N
I
I I
;--
------------
----
------·---
------------------
---'
:
:
NEXT
N :
L
_______
--
---
--
------------
---
----
----
-
------
____
j
--------------------------------------------------------
----------------47

Other manuals for Sharp MZ-700

Related product manuals