Download DS800 Development Suite Software

Transcript
FOR Statement
Name:
FOR ... TO ... BY ... DO ... END_FOR
Meaning:
executes a limited number of iterations, using an integer index variable
Syntax:
FOR <index> := <mini> TO <maxi> BY <step> DO
<statement> ;
<statement> ;
END_FOR;
Operands: index: internal integer variable increased at each loop
mini: initial value for index (before first loop)
maxi: maximum allowed value for index
step: index increment at each loop
The [ BY step ] statement is optional. If not specified, the increment step is 1
Warning: Because the virtual machine is a synchronous system, input variables are not
refreshed during FOR iterations.
This is the "WHILE" equivalent of a FOR statement:
index := mini;
while (index <= maxi) do
<statement> ;
<statement> ;
index := index + step;
end_while;
Example
(* ST program using FOR statement *)
(* this program extracts the digit characters of a string *)
length := mlen (message);
target := ''; (* empty string *)
FOR index := 1 TO length BY 1 DO
code := ascii (message, index);
IF (code >= 48) & (code <= 57) THEN
target := target + char (code);
END_IF;
END_FOR;
DS800 Development Suite 2.1 - Language Reference
465