Unconditional Branches: GOTO,
fOR
.
..
NEXT, GOSUB/RETURN
Unconditional branches change the
f10w
of program execution from the
next sequentia1statement
to
a specified statement.
GOTO
is
the simplest unconditional branch. It designates a line number at
which
program execution
is
to continue.
55
GOTO 1
(1(1
Transfer program control
ta
the
statement
with
Ilne
number
100.
FOR
.
..
NEXT
provides loop control: the statements between the
FOR
statement and the NEXT statement are executed
as
many times
as
specified by
the
FOR
index variable.
1
(1
FOF:
1= 1
TO
1
(1
2(1
'-;:'1
:::~ZI
NEi,:T 1
These statements
will
print
the numbers 1
through
lOin
a vertical
column
on
the
display screen.
The optional
word
STEP
specifies the size of the increment to
be
added
to
the loop index.
J0
FOR
1=10
TO
100
STEP
10
.;~ü
?I
30
t·jEi.,;T 1
These statements
print
the
numbers 10, 20.
30
....
100
on
the
display screen.
GOSUB and RETURN provide the means of branching program control
to
a
subroutine and then returning
to
the statement immediately
following
the
subroutine calI.
Subroutine:
1(100
FOR
I~A
TO
Z
STEP
S
1010
PRIm
1
1020
HE:'·':T
1
11:::1:3(1
F:ETUF:H
Calls:
50
A=I:Z=I(1:S=1
60
GOSUB 10(1(1
200.A=10:Z=10(1:S=10
211:::1
GOSUB 1
(10(1
999
EHIt
These statements illustrate the PRINT loop introduced above structured
as
a
subroutine. The first subroutine cali
will
print
the numbers 1 through 10
(as
in the
first
FOR
NEXT loop example). The second subroutine cali
will
print
the values
10. 20. 30 100
as
in the second
FOR
...
NEXT loop example.
79