Siemens SCL IF ELSE Statement in Structured Control Language(SCL) with Examples

Published on Jun11, 2025 | Category: tia
Share this article:

In Siemens SCL, the IF ELSE statement is a conditional control structure used to execute specific code blocks based on whether a given condition is TRUE or FALSE. It is one of the fundamental constructs in PLC programming and is essential for making logical decisions in automation systems. This conditional statement is highly useful when a program needs to choose between multiple possible actions depending on the current system state or input conditions. The instruction enables the program to conditionally branch the flow based on evaluated conditions, which helps make the logic dynamic and responsive.
The condition itself is an expression that returns a Boolean value — either TRUE or FALSE. These expressions can include logical operators (such as AND, OR, NOT) or comparative expressions (such as =, <, >, <=, >=, <>).
When the IF ELSE instruction is executed, the condition or set of conditions is evaluated in sequence. If a condition evaluates to TRUE, the corresponding block of code is executed. If no conditions are met, the program moves to the ELSE block, if it exists.
This logic structure supports simple, nested, and multiple conditional checks using ELSIF, allowing developers to design complex decision-making structures in a clean, readable format. It is commonly used in real-world industrial applications such as:


By using IF ELSE statements effectively, SCL programmers can create robust, flexible logic that enhances the efficiency and safety of industrial automation systems.

Basic Syntax of IF ELSE Condition in SCL

The basic syntax of an IF ELSE condition in Siemens SCL (Structured Control Language) is shown below. You can use this structure with just an IF condition or extend it with an ELSE or even multiple ELSIF conditions.


IF condition THEN
    // Code to execute if the condition is TRUE
ELSE
    // Code to execute if the condition is FALSE
END_IF

If the condition is satisfied (evaluates to TRUE ), the instructions written after THEN are executed. If the condition is not satisfied (evaluates to FALSE), the instructions after ELSE are executed instead.

After executing either block, the program continues with the next instruction following the END_IF. You can also use multiple IF conditions or ELSIF statements for more complex logic.


IF Condition Example in Siemens SCL

In Siemens SCL (Structured Control Language), the IF condition allows you to execute logic only when a specific condition is TRUE. If the condition is FALSE, the program skips the statements inside the IF block. This is commonly used to control outputs like motors, valves, or alarms based on input status or sensor values.

Example 1: Digital Condition

Logic: If the digital input signal "level_1" is TRUE, set the motor status variable to 1.

SCL Statement:

IF "level_1" = TRUE THEN
    #motor_1_sts := 1;
END_IF;

Explanation: This statement checks if the Boolean input "level_1" is TRUE (e.g., a high-level switch is active). If so, the variable #motor_1_sts is set to 1, which may represent that the motor is running or has been activated.

Example 2: Analog Condition

Logic: If the level value is less than or equal to 30, turn on motor_1.

SCL Statement:

IF #level_1_value <= 30 THEN
    "motor_1" := TRUE;
END_IF;

Explanation: This condition checks if the analog value from a level sensor (represented by #level_1_value) is 30 or below. If so, the motor output "motor_1" is set to TRUE, turning the motor ON to refill or start an action.

img/scl-if-else/scl-if-condition.webp

IF ELSE Condition in Siemens SCL

In Siemens SCL (Structured Control Language), the IF ELSE condition is a complete logical statement used to control the program flow based on TRUE or FALSE conditions. It allows the program to decide between two paths:

This means one of the two blocks will always be executed. The IF ELSE structure is commonly used in automation to switch outputs ON or OFF, depending on sensor inputs, setpoints, or logical decisions.

Example 1: Digital Switch Control

Logic: If switch_1 is ON, turn on motor_1 and turn off motor_2. Otherwise, turn both motors OFF.

SCL Statement:


	
	IF "switch_1"THEN
    // Statement section IF
    "motor_1":=TRUE;
    #motor_2 := FALSE;
ELSE
    "motor_1" := FALSE;
    #motor_2 := FALSE;
END_IF;

Explanation: This IF ELSE statement checks the status of the digital input "switch_1". If it is TRUE (switch is pressed or ON), motor_1 is activated and motor_2 is deactivated. If it is FALSE (switch is OFF), both motors are turned OFF. This kind of control is useful in manual/automatic selector switches or single-operation toggle buttons.

Example 2: Level-Based Motor Control

Logic: If either level_1 is below 30 or level_2 is below 45, run motor_1 and stop motor_2. Otherwise, stop both motors.

SCL Statement:


IF "level_1_sts"<30 OR "level_2_sts"<45 THEN
    // Statement section IF
    "motor_1" := TRUE;
    #motor_2 := FALSE;
ELSE
    "motor_1" := FALSE;
    #motor_2 := FALSE;
END_IF;

Explanation: This IF ELSE structure checks two conditions: whether "level_1_sts" is less than 30 OR "level_2_sts" is less than 45. If either condition is TRUE, motor_1 is turned ON to fill or respond to low level, and motor_2 is kept OFF. If both levels are sufficient (i.e., not below the thresholds), both motors remain OFF. This is typically used in tank level control systems.

img/scl-if-else/scl-if-else-condition.webp

Multiple IF ELSE Conditions in Siemens SCL

In Siemens SCL, multiple IF ELSE conditions are used when different inputs affect outputs in different ways. You can create logical decisions based on temperature sensors, switch status, and other conditions to control motors or other actuators.

Below is an example using a temperature value, a manual switch, and the control of two motors.

Example Logic:

SCL Statement:

	
		IF #temperature > 70 THEN
    "motor_1" := TRUE;
    "motor_2" := FALSE;
ELSIF "manual_switch" THEN
    "motor_1" := FALSE;
    "motor_2" := TRUE;
ELSE
    "motor_1" := FALSE;
    "motor_2" := FALSE;
END_IF;
	

Explanation:

img/scl-if-else/scl-multiple-if-else.webp

Conclusion: IF, IF ELSE, and Multiple IF ELSE in Siemens SCL

Conditional statements in SCL are essential for making decisions based on input conditions. They control the program flow and help automate actions in a flexible and reliable way. Here's a summary of how each structure is used:

These conditional structures help in building logical, efficient, and readable PLC programs. They are commonly used for sensor evaluation, motor control, safety conditions, and operator inputs.