156
Statement Descriptions
Section 5-5
FOR i:=0 TO 100 DO
array[i]:=0;
END_FOR;
IF i=101 THEN
a:=TRUE;
ELSE
a:=FALSE;
END_IF;
• Do not use a FOR statement in which an iteration variable is changed
directly. Doing so may result in unexpected operations.
Example:
FOR i:=0 TO 100 BY 1 DO
array[i]:=0;
i:=i+5;
END_FOR;
• Statements that can be used in the
expression
are assignment state-
ments, IF, CASE, FOR, WHILE, or REPEAT.
• Multiple statements can be executed in the
expression.
Be sure to use a
semicolon (;) delimiter between multiple statements in an
expression
.
• BY
increment_equation
can be omitted. When omitted, BY is taken as 1.
• Variables with integer data types (INT, DINT, LINT, UINT, UDINT, or
ULINT), or equations that return integer values can be specified in the
initial_value, final_value_equation,
and
increment_equation.
Example 1: The iteration is performed when the iteration variable n = 0 to
50 in increments of 5, and the array variable SP[n] is substituted with 100.
FOR n:=0 TO 50 BY 5 DO
SP[n]:=100;
END_FOR;
Example 2: The total value of elements DATA[1] to DATA[50] of array vari-
able DATA[n] is calculated, and substituted for the variable SUM.
FOR n:=0 TO 50 BY 1 DO
SUM:=SUM+DATA[n];
END_FOR;
Example 3: The maximum and minimum values from elements DATA[1] to
DATA[50] of array variable DATA[n] are detected. The maximum value is
substituted for variable MAX and the minimum value is substituted for vari-
able MIN. The value for DATA[n] is between 0 and 1000.
MAX:=0;
MIN:=1000;
FOR n:=1 TO 50 BY 1 DO
IF DATA[n]>MAX THEN
MAX:=DATA[n];
END IF;
IF DATA[n]<MIN THEN
MIN:=DATA[n];
END IF;
END_FOR;
WHILE Statement
■
Summary
This statement is used to execute a specified expression repeatedly for as
long as a specified condition is true.
Summary of Contents for SYSMAC CX-Programmer 9
Page 2: ......
Page 4: ...iv ...
Page 6: ...vi ...
Page 8: ......
Page 16: ...xvi ...
Page 20: ...xx ...
Page 26: ...xxvi Application Precautions 4 ...
Page 27: ...Part 1 Function Blocks ...
Page 28: ......
Page 154: ...128 Procedures Section 3 2 ...
Page 155: ...Part 2 Structured Text ST ...
Page 156: ......
Page 160: ...134 CX Programmer Specifications Section 4 2 ...
Page 206: ...180 Procedures Section 6 1 ...
Page 208: ...182 System defined external variables supported in function blocks Appendix A ...
Page 230: ...204 Revision History ...
Page 231: ......