Structured Text CASE OF Statement

Published on Apr22, 2023 | Category: Structured Text
Share this article:

Structured Text IF_THEN Condition Statements

IF_THEN condition statements execute code if the condition is true. IF_THEN condition statements is very simple. Expression of IF_THEN is

Below is a example of IF_THEN statements so consider a example of two tank filling system with two electrical motor pump one pump for each motor. so in our process we have two tank, two water level transmitter for reading water level of tank, two electrical pump with simple start stop.

img/structured text conditional statements/structured text IF_THEN condition statements.webp

So this code is very simple to just start and stop of motor. So we take next condition and add some more condition to our process so you can understand the conditional statements because it is very important in plc and process.

Structured Text IF_THEN_ELSE Condition Statements

in IF_THEN_ELSE condition statements, code is executed in both true and false condition. while IF_THEN condition statement code executed only in true condition. Expression for IF_THEN_ELSE is

IF_THEN condition statements execute code if the condition is true. And if condition is false then else code executed. Expression of IF_THEN_ELSE is

img/structured text conditional statements/structured text IF_THEN_ELSE condition statements.webp

in above example of IF_THEN_ELSE condition when pump start than pump_start_1_ind_lamp is set to 1 and your indicator lamp will on and predefined alarm list(alarm_list[30]) move to tank_lvl_1_alarm.DATA[1]. if pump not start than pump_start_1_ind_lamp is set to 0 and lamp off, and an error alarm generate error (set of error_alarm move to tank_lvl_1_alarm).The [:=] tells the controller to change value if values already set.

Structured Text IF_THEN_ELSIF Condition Statements

IF_THEN_ELSIF is multiple if condition. If first condition is true than first code is executed, if first condition is false and second condition is true than second code executed and if all two condition is false and third if condition is true than third statement is execute and so on. You can use multiple set of if statements and condition. Expression for IF_THEN_ELSIF statement is

below is the two example of IF_THEN_ELSIF conditional statement. So in our process tank have maximum level 3 meter so we have a condition if the tank level below 1.2 meter than tank low alarm is to set, if tank level is greater than 1.2 and less than 2.2 than alarm set tank filled if tank level is greater than 3 meter than high alarm is set. So our code look like this

img/structured text conditional statements/structured text IF_THEN_ELSIF condition statements.webp

here i am using multiple if statements to show how it works you can make your own logic if found any problem than please share with us.

Structured Text IF…THEN…ELSIF…ELSE Condition Statements

IF…THEN…ELSIF…ELSE is nested if then else condition if first condition is true than first code is executed, if first condition is false and second condition is true than second code executed and so on. And if all above condition is false than else condition is executed. You can use multiple set of if statements and condition. Expression for IF…THEN…ELSIF…ELSE statement is

as above example i am simply add else condition if all the condition is false than else condion is excuted

img/structured text conditional statements/structured text IF…THEN…ELSIF…ELSE condition statements.webp

if else is important role in programming so please do more practice. I tried to explain as much as possible. Without logical operators conditional statements is not complete we discuss on logical operators in next article. All example are sample code.