Jumps And Loops; Jump Unconditionally; Jump Depending On A Value - Mitsubishi QD51 Programming Manual

Logic controller
Hide thumbs Also See for QD51:
Table of Contents

Advertisement

3 LET'S CREATE AND EXECUTE A PROGRAM

3.6 Jumps and Loops

3.6.1 Jump unconditionally

Will it ever stop? ......

3.6.2 Jump depending on a value

10 INPUT"A=" ;A
20 ON A GOTO
30 END
40 PRINT "ONE"
50 PRINT "TWO"
60 PRINT "THREE" GOTO 10
RUN
A=?2
A=?3
A=?4
OK
3 - 23
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______________
ON GOTO___________
FOR-NEXT__________
WHILE-WEND________
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 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.
40,50,60
GOTO 10
GOTO 10
Enter
TWO
Enter
When A=4, there is no jump destination,
THREE
so the following line is executed.
The next line is END, so the program ends.
Jump unconditionally
Jump depending on a value
Loop for the number of times specified
Loop while a certain condition is met
The execution is moved to the line with
the line number specified by the GOTO
instruction.
P ress th e
B re ak
to force 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 .
Jump destination line number when A is 1.
Jump destination line number when A is 2.
Jump destination line number when A is 3.
MELSEC-Q
ke y o r the
C trl +
C
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.
ke ys
3 - 23

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ad51h-s3Qd51-r24A1sd51s

Table of Contents