11 - 400 11 - 400
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
WHILE WEND
Instruction
WHILE to While END
• These instructions are used to execute the group of instructions between WHILE and
WEND repeatedly, while the specified condition holds.
Syntax
WHILE <expression>
WEND
expression
• • • •
Specify the condition under which the instructions
enclosed by the WHILE to WEND instructions are
executed repeatedly.
Examples
WHILE K>5
to
WEND
• • • •
Repeats the instructions between the WHILE to
WEND instructions as long as the value of K is
greater than 5.
Description
• The WHILE to WEND instructions are used to execute a selected processing under a
given condition. The group of instructions from the WHILE instruction to the WEND
instruction are executed repeatedly while the condition specified in <expression> holds.
• A pair of WHILE and WEND instructions constitute one loop together.
The difference from the FOR to NEXT instructions is instead of specifying the number of
repetitions of the execution, a condition for repeated execution is specified.
• If the value of <expression> is True (any other value than 0), the instructions from the one
immediately after the WHILE until the WEND instruction are executed and then the
execution returns to the WHILE instruction to evaluate <expression> again. This routine is
repeated while the value of <expression> is True. If the value of <expression> is False (0),
the instruction immediately after the WEND instruction is executed.
• The repeated processing between the WHILE to WEND instructions is stopped if a GOTO
or RESUME instruction is executed inside the WHILE to WEND loop in an error handling
routine.
• Lines where WHILE or WEND instructions are written can be specified as the branch
destination of a GOTO instruction, etc.
• It is possible to write the WHILE to WEND instructions within a loop created by another pair
of WHILE-WEND instructions.
• When using more than one pair of WHILE to WEND instructions, take precautions so that
the inner WHILE to WEND loop is completely contained within the outer loop.
WHILE
WEND
WEND
WHILE
:
WHILE
WEND
WEND
WHILE
:
(Incorrect)
(Correct)