Mitsubishi Electric MELSEC iQ-R Series Programming Manual page 68

Hide thumbs Also See for MELSEC iQ-R Series:
Table of Contents

Advertisement

Iteration statements
Control
Format
statement
■FOR...DO
FOR<iteration variable
initialization>
END_FOR;
■WHILE...DO
WHILE<boolean
expression>DO
END_WHILE;
■REPEAT...UNTIL
REPEAT
END_REPEAT;
■EXIT
EXIT;
6 STRUCTURED TEXT LANGUAGE
66
6.1 Configuration
Description
Data to be used as an iteration variable is initialized.
One or more statements between the DO statement and the END_FOR
TO<final value>
statement are executed repeatedly, adding or subtracting the initialized
BY<increase
iteration variable according to the increase expression until the final
expression>DO
value is exceeded.
<statement>;
The iteration variable after the FOR...DO statement is completed
retains the value at the end of the processing.
One or more statements are executed while the boolean expression
(conditional formula) is TRUE.
<statement>;
The boolean expression is determined before execution of the
statement and, if it is FALSE, any statement in the DO...END_WHILE
statement is not executed. Since <boolean expression> in the WHILE
statement is only necessary to return TRUE or FALSE as the result,
any expression that can be specified in <boolean expression> of the IF
statement can be used.
One or more statements are executed while the boolean expression
<statement>;
(conditional formula) is FALSE.
UNTIL<boolean
The boolean expression is determined after execution of the statement
expression>
and, if the value is TRUE, any statement in the REPEAT...UNTIL
statement is not executed. Since <boolean expression> in the REPEAT
statement is only necessary to return TRUE or FALSE as the result,
any expression that can be specified in <boolean expression> of the IF
statement can be used.
This statement can be used only within an iteration statement to
terminate the iteration statement in the middle of processing.
When the EXIT statement is reached during execution of the iteration
loop, the iteration loop processing after the EXIT statement is not
executed. The program execution continues from the line next to the
one where the iteration statement was terminated.
Example
FOR intV1 := 0
TO 30
BY 1 DO
intV3 := intV1 + 1;
END_FOR;
WHILE intV1 = 30 DO
intV1 := intV1 + 1;
END_WHILE;
REPEAT
intV1 := intV1 + 1;
UNTIL intV1 = 30
END_REPEAT;
FOR intV1 := 0
TO 10
BY 1 DO
IF intV1 > 10 THEN
EXIT;
END_IF;
END_FOR;

Advertisement

Table of Contents
loading

Table of Contents