Exploring the IF statement
The most rudimentary control statement that all PLC developers will need to master is the IF
statement. As the name suggests, this command will run a block of code if, and only if, a certain logical expression evaluates to True
. Much as with logical expressions, the IF
statement must be mastered, especially for PLC programming.
IF statement syntax
The IEC 61131-3 syntax for the IF
statement is somewhat like the VAR
declaration block. The basic structure for the IF
statement is as follows:
IF <expression> THEN //code to run END_IF
For this structure, the expression is a logical expression such as determining if two values are equal. In between IF
and END_IF
is what’s called the body. The body is the code that will run when the expression is True
. Technically, you can have as much code in the body as you want, but it is advisable to keep the body as short as possible. To really understand the IF
statement...