×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | OMRON CX-Programmer Structured Text If Statements
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


OMRON CX-Programmer Structured Text If Statements

IF statement is a type of control statement in Structured Text programming. if statement execute statement if the result of expression is true, otherwise else condition is executed. in a Structured program you can join multiple expression by using logical operator like and, or, xor and not. result of if expression is Boolean value(true or false) based on these expression statement executed. in a Structured text program you can use multiple if statement. multiple if statements is known as nested if statements. There can be several ELSIF statements within an IF Statement, but only one ELSE statement.


What Is A Expression Of Structured Text If Statements

IF statements execute code if the condition is true other wise else condition execute. You can also define a condition without else statements. expression for if statements as below
  • IF expression1 THEN statement-list1;
  • ELSIF expression2 THEN statement-list2;
  • ELSE statement-list3;
  • END_IF;
expression1 and expression2 evaluate a Boolean value (true or false) if the expression1 condition is true than statement-list1 execute otherwise expression2 executed if expression2 is true then statement-list2 executed otherwise else condition is executed.


Structured Text IF Statement without Else

if condition without else execute statement if the expression result is true otherwise no action perform. Below is the example of Structured Text IF Statement without Else

Structured Text IF Statement without Else

in this example if the push button is operated it means expression have true condition so statement executed to run a motor. if push button is not operated than expression result is false and no action perform.


Structured Text IF else Statement

IF ELSE statement is complete set for a expression as we known result of Boolean expression is true or false when we use else than if all expression result is false than else condition execute. in the if else condition if the expression result is true than statement-list1 executed. if the expression result is false than else statement execute. below is the example of Structured Text IF else Statement

Structured Text IF else Statement

in above example of Structured Text IF else Statement when push button operated than motor on otherwise a alarm message array set an alarm to plc. alarm list define on array of string. array in plc we discuss latter.


Structured Text Nested If Statement

a nested if statement is multiple if statement placed in a if statement. A nested if statement used for making a multiple decision making program. a example describe the Structured Text Nested If Statement.

Structured Text Nested If Statement

in above example of multiple if statement when water level is higher than set point then feed motor stop and gate open to release water from tank.if the set point of water level below to set point than feed motor start and gate close. in third if statement if the water level between a range than feed motor start and valve open for supply water. for maintaining a water feed motor run. if not of the any above condition is true than alarm message is generated for issues.


Structured Text ELSIF Statement

an alternative conditional branch in addition to the "if" statement. The "ELSIF" statement allows for multiple conditions to be evaluated in a sequence, and if the condition in the "if" statement is not met, the program evaluates the next "ELSIF" condition, and so on until a condition is met or until there are no more "ELSIF" conditions left to evaluate. you can use multiple elseif statement.

Structured Text ELSIF Statement

in above example of Structured Text ELSIF Statement if the first limit switch operated than gate no 1 open and other remain close else if second limit switch operated than second gate open ELSIF third limit switch is operated than gate no 3 open otherwise all gate close.


Structured Text IF statement for multiple expression

logical operator combine multiple expression these logical operator are and operator, or operator, xor operator, not operator. Logical operators are used in if statements to combine multiple conditions. result of these Logical operators combine into a single condition.

Structured Text IF statement for multiple expression

in this example of Structured Text IF statement for multiple expression. for a momentary push button When the button is pressed, it makes contact between two conductive parts, allowing current to flow through the circuit. When the button is released, the contact is broken, and the current stops flowing. so the logic for start motor using momentary push button is a above example. it is simple demonstration of program.


 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

comment