11 - 164 11 - 164
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
ON GOSUB
Instruction
ON to GOSUB
• Branches the program execution to one of several specified line numbers depending on
the value of the specified expression.
ON <expression> GOSUB <line number>[,<line number>…]
expression
• • • •
Branches to the specified line number depending on
the value of the expression.
Syntax
line number
• • • •
Specify the line number to which the execution is
branched.
Examples
ON A GOSUB 200, 300,
400
• • • •
Executes the subroutine at line 200 if the value of A
is 1, the subroutine at line 300 if A is 2, and the
subroutine at line 400 if A is 3.
Description
• The ON to GOSUB instruction branches the program execution to one of several specified
line numbers depending on the value of the specified expression.
• Digits after the decimal points are truncated if the value of <expression> is not an integer.
• The execution moves to the next instruction if the value of <expression> is 0 or greater
than the number of specified line numbers, which should be 255 or less.
• An “Illegal function call” error occurs if the value of <expression> is negative or greater than
255.
• A label name can be used instead of an actual line number for <line number>.
• Each of the line numbers specified in the ON to GOSUB instruction must be specified as
the corresponding starting line numbers of the processing routines.
• If an instruction is written following the ON to GOSUB instruction, the ON to GOSUB
instruction is executed when it is returned by the RETURN instruction after the execution
of the processing routine.
ON A GOSUB 100 , 200 , 300 : instruction
Instruction
Line 200
Line 100
RETURN
RETURN
A=1
A=2
A=3
Line 300
RETURN
ON GOSUB
Содержание A1SD51S
Страница 183: ...11 13 11 13 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS RUN Before swap A 0 H924 A 1 H1159 After swap A 0 H1159 A 1 H924 OK...
Страница 331: ...11 161 11 161 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CON ON OFF STOP and ZOPEN functions and Section 7 4...
Страница 557: ...11 387 11 387 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the CHR SPACE and SPC functions...
Страница 629: ...11 459 11 459 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZOPEN ZSEND and ZCNTL instructions and Section 7 3 4...
Страница 645: ...11 475 11 475 MELSEC Q 11 INSTRUCTIONS AND FUNCTIONS REMARK See the ZEVENT ZSIGNAL and DEF ZEVENT instructions...