3 - 25 3 - 25
MELSEC-Q
3 LET'S CREATE AND EXECUTE A PROGRAM
3.6.4 Loop while a certain condition is met
Use the WHILE-WEND instructions to repeat execution of instructions only while a
certain condition is met.
10 N=0
20 WHILE N<4
30 PRINT N;
40 N=N+1
50 WEND
60 END
RUN
0 1 2 3
OK
Instructions in this range are repeated.
This is a condition that is true as long as N is less than 4.
The instructions in the loop are repeated while the condition stated immediately after
WHILE is met.
For details on how to specify conditional expressions, see Section 3.7.
The WHILE-WEND instructions are loop instructions very similar to the FOR-NEXT
instructions, but it is the WHILE instruction that determines whether or not the loop
should continue. Therefore, if a condition is not met from the beginning, the instructions
between the WHILE and the WEND will not be executed even once.
10 FOR N=1 TO 1
20 PRINT N
30 NEXT N
40 END
RUN
1
OK
10 N=1
20 WHILE N<1
30 PRINT N
40 WEND
50 END
RUN
1
OK
FOR-NEXT loop
WHILE-WEND loop
The NEXT instruction determines
whether the loop should continue.
Содержание 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...