Omron NJ-series User Manual page 282

Machine automation controller cpu unit software
Hide thumbs Also See for NJ-series:
Table of Contents

Advertisement

• Do not write code that directly modifies the FOR variable inside the FOR construct. Unintended
operation may result.
Example:
FOR i:=0 TO 100 BY 1 DO
X[i]:=0;
i:=i+INT#5;
END_FOR;
• You can write any of the statements on multiple lines. Separate statements with a semicolon (;).
• You can omit BY<increment/decrement>. If it is omitted, the statement is executed with an incre-
ment value of 1.
• You can specify an integer (SINT, INT, DINT, LINT, USINT, UINT, UDINT, or ULINT) variable or
integer value for the <initial_value>,<end_value>, and <increment/decrement>. You can also
specify a function that returns an integer value.
Example 1:
FOR n := 0 TO 50 BY 5 DO
END_FOR;
Example 2:
IF a THEN
END_IF;
Example 3:
MAX :=0;
MIN :=1000;
FOR n :=1 TO 50 BY 1 DO
END_FOR;
NJ-series CPU Unit Software User's Manual (W501)
A value of 100 is assigned to array variable elements SP[n]. The FOR variable is
variable n, the initial value is 0, the end value is 50, and the increment is 5.
SP[n] := 100;
The total of elements DATA[1] through DATA[50] of array variable elements DATA[n]
is calculated and the result is assigned to the variable SUM.
FOR n := 0 TO 50 BY 1 DO
DATA[n]:= 1 ;
END_FOR;
FOR n := 0 TO 50 BY 1 DO
SUM:= SUM + DATA[n] ;
END_FOR;
a:=FALSE;
The maximum and minimum values of elements DATA[1] through DATA[50] of array
variable elements DATA[n] are found. The maximum value is assigned to the MAX
variable, and the minimum value is to the MIN variable. The value of DATA[n] is from
0 to 1,000.
IF DATA[n] > MAX THEN
MAX :=DATA[n];
END_IF;
IF DATA[n] < MAX THEN
MIN :=DATA[n];
END_IF;
6 Programming
6
6-95

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents