38
GOSUB and RETURN Statements
Purpose:
To branch to and return from a subroutine
Format:
GOSUB <line>
<line> is the first line number of the subroutine.
Remarks:
A subroutine may be called any number of times in a program, and a subroutine
may be called from within another subroutine.
The RETURN statement(s) in a subroutine causes execution to branch back to
the statement following the most recent GOSUB statement.
A subroutine may contain more than one RETURN statement should logic dic-
tate a return at different points in the subroutine.
Subroutines can appear anywhere in the program, but it is recommended that
subroutines be readily distinguishable from the main program.
To prevent inadvertent entry into a subroutine, the subroutine may be preceded
by a STOP, END, or GOTO statement to direct program execution around the
subroutine.
Program Example:
10
T = Time
20
GOSUB 100
30
{stuff}
40
.
50
.
60
.
90
GOTO 150
100
110
T = T + TIME
120
RETURN
130
{stuff}
GOTO Statement
Purpose:
To unconditionally branch program execution to the specified line
number
Format:
GOTO <line>
<line> is a valid line number.
Remarks:
If <line> is a non-executable statement, execution will proceed at the first ex-
ecutable statement encountered after <line>.
IF...THEN Statements
Purpose:
To control program flow based on the results returned by an
arithmetic or logical expression
Format:
IF <expression> [ , ] THEN <statement(s)> or <line>
[ELSE <statement(s)> or <line>]
IF <expression> [ , ] GOTO <line>
[[ , ] ELSE <statement(s)> or <line>]
Example:
IF B=10 THEN PRINT “hello” ELSE 500
Commands, Statements, and Functions
Содержание C500-ASC04
Страница 1: ...C500 ASC04 ASCII Unit Operation Manual Revised February 2001 ...
Страница 5: ...iv ...
Страница 7: ...vi ...