IF Statement using Structured Text - IEC-61131-3

We use if statements when we have to branch through multiple conditions.

//structured Text Declaration

button: bool;
relayCoil: bool;
//Structured Text IF Statement

IF button = 1 THEN
  relayCoil:=1;
END_IF

If we have two conditions we use IF-ELSE: .

//structured Text Declaration

button: bool;
relayCoil: bool;
//Structured Text IF Statement

IF button = 1 THEN
  relayCoil:=1;

ELSE
  relayCoil:=0;

END_IF

If we have more than two conditions, and only one at a time should be excuted, we use IF-ELSIF-ELSE: .

//structured Text Variables Declaration

button1:bool;
relayCoil1:bool;
button2:bool;
relayCoil2:bool;
relayCoil3:bool;
          
//structured Text IF-ELSIF-ELSE

IF button1 = 1 THEN
  relayCoil1 := 1;

ELSIF Button2 = 1 THEN
  relayCoil2 := 1;

ELSE
  relayCoil3 := 1;

END_IF
	

If we have multipe conditions, and multiple conditions can be activated at a time should be excuted, we use IF-IF-IF: .

//structured Text Variables Declaration

  button1    :bool;
  relayCoil1 :bool;
  button2    :bool;
  relayCoil2 :bool;
  button3    :bool;
  relayCoil3 :bool;
            
//structured Text IF-IF-IF

IF button1 = 1 THEN
  relayCoil1 := 1;
END_IF

IF button1 = 2 THEN
  relayCoil1 := 1;
END_IF

IF button1 = 3 THEN
  relayCoil1 := 1;
END_IF
  	

© Copyright 2022 Advanced PLC. All rights reserved.