11 - 401 11 - 401
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
FOR to TO
WEND
NEXT
WHILE
:
(Incorrect)
(Correct)
NEXT
WEND
WHILE
:
FOR to TO
If the WHILE to WEND instructions are used in combination with the FOR to NEXT
instructions, take precautions so that the inner loop is completely contained
within the outer loop.
Program Example
10 ' This program repeats a calculation while the specified condition holds
20 I=1
:
' Sets the initial value
30 WHILE I<10
:
' Repeats until I exceeds 10
40 PRINT "I=":I
:
' Displays the values of I
50 I=I+1
:
' Adds 1 to I
60 WEND
70 PRINT "I exceeded 10"
:
' Displays the result
80 END
RUN
I=1
I=2
I=3
I=4
I=5
I=6
I=7
I=8
I=9
I exceeded 10
OK
REMARK
See the FOR to NEXT instructions and Section 3.6.4.