Omron WS02-CXPC1-V9 - V9 Operation Manual page 182

Table of Contents

Advertisement

Statement Descriptions
WHILE Statement
156
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
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
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
IF DATA[n]>MAX THEN
MAX:=DATA[n];
END IF;
IF DATA[n]<MIN THEN
MIN:=DATA[n];
END IF;
END_FOR;
■ Summary
This statement is used to execute a specified expression repeatedly for as
long as a specified condition is true.
BY 5 DO
BY 1 DO
BY 1 DO
Section 5-5

Advertisement

Table of Contents
loading

This manual is also suitable for:

Sysmac cx-programmer 9Sysmac ws02-cxpc1-v9

Table of Contents