IF_THEN

Use IF_THEN to complete an action when specific conditions occur.
Operands
IF bool_expression THEN
<statement>;
Operand
Type
Format
Enter
Bool_
expression
BOOL
Tag expression
BOOL tag or expression that evaluates to a BOOL value
(BOOL expression)
Description
The syntax is described in the table.
Structured Text Syntax_If_Then
To use ELSIF or ELSE, follow these guidelines.
To select from several possible groups of statements, add one or more ELSIF statements.
Each ELSIF represents an alternative path.
Specify as many ELSIF paths as you need.
The controller executes the first true IF or ELSIF and skips the rest of the ELSIFs and the ELSE.
To do something when all of the IF or ELSIF conditions are false, add an ELSE statement.
The table summarizes different combinations of IF, THEN, ELSIF, and ELSE.
If
And
Use this construct
Doing something if or when conditions are true
Do nothing if conditions are false
IF_THEN
Do something else if conditions are false
IF_THEN_ELSE
Selecting alternative statements or groups of statements based on input conditions
Do nothing if conditions are false
IF_THEN_ELSIF
Assign default statements if all conditions are false
IF_THEN_ELSIF_ELSE
Affects Math Status Flags
No
Major/Minor Faults
None.
Examples
Example 1
IF…THEN
If performing this
Enter this structured text
IF rejects > 3 then
IF rejects > 3 THEN
conveyor = off (0)
conveyor := 0;
alarm = on (1)
alarm := 1;
END_IF;
Example 2
IF_THEN_ELSE
If performiing this
Enter this structured text
If conveyor direction contact = forward (1) then
IF conveyor_direction THEN
light = off
light := 0;
Otherwise light = on
ELSE
light [:=] 1;
END_IF;
The [:=] tells the controller to clear light whenever the controller does the following :
Enters the RUN mode.
Leaves the step of an SFC if you configure the SFC for Automatic reset. (This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
Example 3
IF…THEN…ELSIF
If performing this
Enter this structured text
If sugar low limit switch = low (on) and sugar high limit switch = not high
(on) then
IF Sugar.Low & Sugar.High THEN
inlet valve = open (on)
Sugar.Inlet [:=] 1;
Until sugar high limit switch = high (off )
ELSIF NOT(Sugar.High) THEN
Sugar.Inlet := 0;
END_IF;
The [:=] tells the controller to clear Sugar.Inlet whenever the controller does the following :
Enters the RUN mode.
Leaves the step of an SFC if you configure the SFC for Automatic reset. (This applies only if you embed the assignment in the action of the step or use the action to call a structured text routine via a JSR instruction.)
Example 4
IF…THEN…ELSIF…ELSE
If performing this
Enter this structured text
If tank temperature > 100
IF tank.temp > 200 THEN
then pump = slow
pump.fast :=1; pump.slow :=0; pump.off :=0;
If tank temperature > 200
ELSIF tank.temp > 100 THEN
then pump = fast
pump.fast :=0; pump.slow :=1; pump.off :=0;
Otherwise pump = off
ELSE
pump.fast :=0; pump.slow :=0; pump.off :=1;
END_IF;
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.