152
Structured Text (ST Language) Specifications
Appendix B
Example 2: The total value of elements DATA[1] to DATA[50] of array variable 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 sub-
stituted for variable 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.
Reserved Words
WHILE, DO, END_WHILE
Statement Syntax
WHILE
<
condition
>
DO
<
expression
>
;
END_WHILE;
Processing Flow Chart
Usage
Use the WHILE statement when the number of iterations has not been determined beforehand (depends on
the condition being met) to repeat specified processing for the duration that the condition is met. This state-
ment can be used to execute processing while the condition equation is true only (pretest loop).
Description
Before the
expression
is executed, the
condition
is evaluated.
If the
condition
is true, the
expression
is executed. Afterwards, the
condition
is evaluated again. This process is
repeated. If the
condition
is false, the
expression
is not executed and the
condition
evaluation ends.
Iteration
Condition
Expression
False
True
End
Содержание CS1-H Series
Страница 3: ...iv...
Страница 5: ...vi...
Страница 7: ...viii TABLE OF CONTENTS...
Страница 15: ...xvi Application Precautions 4...
Страница 151: ...136 Procedures Section 3 2...
Страница 153: ...138 Data Types Appendix A...
Страница 177: ...162 External Variables Appendix C...
Страница 181: ...166 Revision History...