IF_THEN condition statements execute code if the condition is true. IF_THEN condition statements is very simple. Expression of IF_THEN is
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
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.
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
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.
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
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.