Arithmetic status flags, Fault conditions, Example 1 – Rockwell Automation Logix5000 Controllers Structured Text Programming Manual User Manual

Page 32

Advertising
background image

32

Publication 1756-PM007D-EN-P - November 2012

Chapter 1 Program Structured Text

These diagrams show how a WHILE...DO loop executes and how an EXIT
statement leaves the loop early.

Arithmetic Status Flags:

Not affected

Fault Conditions:

Example 1:

While the bool_expression is true, the controller
executes only the statements within the
WHILE…DO loop.

To stop the loop before the conditions are true, use an
EXIT statement.

Statement 1

Statement 2

Statement 3

BOOL expression

True

False

Rest of the routine

Yes

No

Statement 1

Statement 2

Statement 3

BOOL expression

True

False

Rest of the routine

A major fault will occur if

Fault type

Fault code

The construct loops too long

6

1

If you want this

Enter this structured text

The WHILE...DO loop evaluates its conditions first. If the
conditions are true, the controller then executes the
statements within the loop.

This differs from the REPEAT...UNTIL loop because the
REPEAT...UNTIL loop executes the statements in the construct
and then determines if the conditions are true before
executing the statements again. The statements in a
REPEAT...UNTIL loop are always executed at least once. The
statements in a WHILE...DO loop might never be executed.

pos := 0;

While ((pos <= 100) & structarray[pos].value <> targetvalue)) do

pos := pos + 2;

String_tag.DATA[pos] := SINT_array[pos];

end_while;

Advertising