Omron SYSMAC C200H-ASC02 Operation Manual page 46

Ascii unit
Hide thumbs Also See for SYSMAC C200H-ASC02:
Table of Contents

Advertisement

BASIC Language
GOSUB and RETURN Statements
36
<var> is used as a counter. The first numeric expression (<x>) is the initial
value of the counter. The second numeric expression (<y>) is the final value
of the counter.
The program lines following the FOR statement are executed until the NEXT
statement is encountered. Then the counter is incremented by the amount
specified by STEP.
A check is performed to see if the value of the counter is now greater than
the final value (<y>). If it is not greater, execution branches back to the first
statement after the FOR statement and the process is repeated. If it is great-
er, execution continues with the statement following the NEXT statement.
This is a FOR...NEXT loop.
If STEP is not specified, the increment is assumed to be one. If STEP is neg-
ative, the counter will count down instead of up. In this case, the loop will be
executed until the counter is less than the final value.
The body of the loop will never be executed if the initial value of the loop is
greater than the final value.
NESTED LOOPS
FOR...NEXT loops may be nested, that is, a loop can be placed inside of
another loop. When loops are nested, each loop must have a unique variable
name for its counter. The NEXT statement for the inside loop must come be-
fore the NEXT statement for the outer loop.
If nested loops have the same endpoint, the same NEXT statement can be
used for both of them.
If a NEXT statement is encountered before its corresponding FOR statement,
an error message is issued and execution is terminated.
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 subrou-
tine 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
dictate 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 preced-
ed 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
.
Section 4-2

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents