App.g-8 – Yokogawa GC8000 Process Gas Chromatograph User Manual
Page 507

App.G-8
IM 11B08A01-01E
Explanation Used in pair, FOR and NEXT statements execute as described below.
(1) Calculates initial value, fi nal value and increment.
(2) Substitutes variable with initial value.
(3) Executes statements between the FOR statement and the corresponding
NEXT statement. However, when either the GOTO statement or GOSUB
statement is executed during the process, the control can be moved out of the
FOR loop (part that enclosed by the FOR and NEXT statements).
(4) After reaching the NEXT statement corresponding to the FOR, the variable will
be incremented (increased when the variable value is positive and decreased
when it is negative).
(5) Compares the value of the variable with the fi nal value and executes as follows
depending on the increment.
When increment is positive:
Go back to (3) when variable is less than or equal (≤) to fi nal value.
Execute the statement after NEXT statement when variable is greater
than (>) the fi nal value.
When increment is negative or zero:
Go back to (3) when the variable is greater than or equal (≥) to the fi nal
value.
When variable is less than the fi nal value, execute the statement after the
NEXT statement.
Calculation will stop when the fi nal value and value of the increment are
entered into the FOR statement. If the values of variables in the equations are
changed during the process from FOR to NEXT, the fi nal value and increment
will also change.
When the program is exited by the GOTO statement during the process
between the FOR and NEXT, the values of the variables will be saved and can
be used again.
When the program is exited between the FOR and NEXT while processing (5),
the values of the variables will be saved.
When the values of the variables are changed in the process before the
NEXT statement, those values are used to repeat processes (2) and (3). Zero
increment causes an infi nite loop.
Also, if increment is set as a numerical value with decimal points, there is
the risk that value of the fi nal value will not be calculated due to an error in
calculating real numbers.
Notes on programming
When using one pair of the FOR and NEXT statements in another FOR to
NEXT range, the former pair must be within the range of the latter FOR to
NEXT. Both the line and execution order must be correct.
GOSUB/RETURN Statement
Function
Performs divergence to subroutine and reversion from subroutine.
Format GOSUB
label
RETURN
Explanation The GOSUB statement moves the control from the specifi ed label to the
subroutine. The subroutine processing is completed with the execution of the
RETURN statement. The program is moved to the statement that follows the
GOSUB statement.
By using the GOSUB statement, the same process content can be used
repeatedly in the program.
Some subroutines are able to call other subroutines.
Error will occur when the specifi ed label is not in the program. Error will also
occur when the RETURN statement is executed without executing the GOSUB
statement. Furthermore, error will occur when the GOSUB statement is used to
move the control to the block subroutine (FOR/NEXT, IF..THEN/ENDIF, IF..THEN/
ELSE/ENDIF, WHILE/END WHILE).
2nd Edition : May 11, 2012-00