GOTO
GOTO
GO
TO
liIIC·
ilUIll
bel
Examples:
The
GOTO
statement allows you
to
transfer control
backward
or
forward within a program. Whenever the computer reaches a
GOTO
statement.
it
will always jump to the statement with the
specified line-number.
This
is
called an unconditional branch.
In the program
on
the right, line 170 is
an
unconditional branch.
The
computer always skips to line 140
at
this point.
Lme
16U IS
a conditional branch (see
"IF·THEN·ELSE").
The
computer
jumps to line 180 only if
COUNT
and DAYS are equal.
If
you should tell the computer to skip to a line-number that does
not exist in your program, the program
will stop running
and
print
the
message
"BAD
LINE
NUMBER."
Note that the space between the words GO and
TO
is optional.
User's Reference Guide
>NEW
>100
REM
HOW
MANY
GIFTS
ON
THE
12
DAYS
OF
CHRISTMAS?
>110 GIFTS=O
:>120
DAYS=1
>130
COUNT=O
>140
COUNT=COUNT+1
>150 GIFTS=GIFTS+1
>160
IF
COUNT=DAYS
THEN
180
>170 GaTe 140
>180
DAYS=DAYS+1
>190 IF
DAYS<=12
THEN
130
>200
PRINT
"TOTAL
NUMBER
OF
G
IFTS
IS";GIFTS
>210
END
>RUN
TOTAL
NUMBER
OF
GIFTS IS 78
**
DONE
**
II-49