6-99
6 Programming
NJ-series CPU Unit Software User’s Manual (W501)
6-5 Programming Languages
6
6-5-3 Structured Text Language
Process Flow Diagram:
Application:
Use this type of repeat construct when you do not know how many times to repeat a process (i.e.,
when you do not know how many times based on the condition) and you want to repeat a process
for as long as a certain condition is met after processing. Use this type of repeat construct to deter-
mine repeat execution based on the result of the execution of a process (post-evaluation repeat con-
struct).
Description:
First, <statement> is executed unconditionally. Then the <condition_expression> is evaluated.
If <condition_expression> is FALSE, <statement> is executed.
If <condition_expression> is TRUE, <statement> is not executed and the REPEAT construct is
exited.
Precautions:
• REPEAT must always be used together with END_REPEAT.
• Even if the <condition_expression> is TRUE before <statement> is executed, <statement> is exe-
cuted.
In other words, <statement> is always executed at least one time.
• <statement> can contain multiple lines of code for the statement. Separate statements with a
semicolon (;).
• You can also specify a BOOL variable (including functions that return a BOOL value) for the condi-
tion expressions instead of an actual expression.
Example:
Example 1: Numbers from 1 to 10 are added and the values are assigned to the variable TOTAL.
• If you do not write correct condition expressions, the program execution time increases and may
cause a Task Period Exceeded Error.
Example:
intVar := INT#1;
REPEAT
intVar := intVar + INT#1;
UNTIL intVar = INT#0
END_REPEAT;
A := 1;
TOTAL := 0;
REPEAT
TOTAL := TOTAL + A;
A := A+INT#1;
UNTIL A>10
END_REPEAT;
Condition
expression
TRUE
Statement
FALSE
Repeated
End