3 - 23 3 - 23
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
3.6 Jumps and Loops
BASIC programs are typically executed in increasing order of line numbers. However,
there are instances when it is better that the order of execution is changed. AD51H-
BASIC has the following instructions to change the order in which execution is carried
out in a program.
GOTO______________
Jump unconditionally
ON GOTO___________
Jump depending on a value
FOR-NEXT__________
Loop for the number of times specified
WHILE-WEND________
Loop while a certain condition is met
3.6.1 Jump unconditionally
Use the GOTO instruction to jump to the specified location unconditionally.
10 A=1
20 PRINT A
30 A=A+1
40 GOTO 20
RUN
1
2
3
…
The execution is moved to the line with
the line number specified by the GOTO
instruction.
P ress th e B re ak ke y o r the C trl + C ke ys
to forc e a n exe cutio n to sto p . A fter a
"B rea k in " m e ssag e is d ispla yed ,
it w ill re tu rn to O K .
Will it ever stop? ……
3.6.2 Jump depending on a value
The ON-GOTO instruction expands the functionality of the GOTO instruction; it is
possible to jump to a different line depending on the value of a variable. This allows
multiple destinations to be specified for the jump.
The jump destination can
be changed depending on
the value of the variable
after ON.
There is no restriction
on the number of line
numbers that can be
written after the
GOTO instruction.
10 INPUT"A=" ;A
20 ON A GOTO 40,50,60
30 END
40 PRINT "ONE" GOTO 10
50 PRINT "TWO" GOTO 10
60 PRINT "THREE" GOTO 10
RUN
A=?2
TWO
A=?3
THREE
A=?4
OK
Enter
Enter
Jump destination line number when A is 1.
When A=4, there is no jump destination,
so the following line is executed.
The next line is END, so the program ends.
Jump destination line number when A is 2.
Jump destination line number when A is 3.
Содержание 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...