Inst ToolsInst ToolsInst Tools
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
Search
  • Books
  • Software
  • Projects
  • Process
  • Tools
  • Basics
  • Formula
  • Power Plant
  • Root Cause Analysis
  • Electrical Basics
  • Animation
  • Standards
  • 4-20 mA Course
  • Siemens PLC Course
Reading: If Else Statement in SCL Language
Share
Notification Show More
Font ResizerAa
Inst ToolsInst Tools
Font ResizerAa
  • Courses
  • Design
  • PLC
  • Interview
  • Control System
Search
  • Courses
  • Automation
    • PLC
    • Control System
    • Safety System
    • Communication
    • Fire & Gas System
  • Instrumentation
    • Design
    • Pressure
    • Temperature
    • Flow
    • Level
    • Vibration
    • Analyzer
    • Control Valve
    • Switch
    • Calibration
    • Erection & Commissioning
  • Interview
    • Instrumentation
    • Electrical
    • Electronics
    • Practical
  • Q&A
    • Instrumentation
    • Control System
    • Electrical
    • Electronics
    • Analog Electronics
    • Digital Electronics
    • Power Electronics
    • Microprocessor
Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Inst Tools > Blog > PLC Tutorials > If Else Statement in SCL Language

If Else Statement in SCL Language

Learn about the If Else Statement in SCL Language and how it simplifies programming with conditional logic.

Last updated: March 25, 2025 2:29 pm
Viral Nagda
PLC Tutorials
No Comments
Share
6 Min Read
SHARE

As seen in earlier posts, one of the most used constructs in SCL language is an if else statement. This is the most used statement in ST language of overall automation platforms. What makes it popular is its relative simplicity in defining them. If a programmer at least learns this construction only, then too he can make a whole program in SCL language. In this post, we will see how we can write different styles in an if else statement.

Contents
What is the if else and if statement?How to write an if statement?How to write an if else statement?

What is the if else and if statement?

As the name describes, an if else statement is a construction which checks the condition first and then executes a statement inside it if true. Or else, it will execute another statement if false. So either way, it will execute something or the other. A simple statement apart from if else is an only if statement. In this case, if the condition is true, then only the statement inside it will execute. Otherwise, it will skip the whole construct and go to the next line after end_if line. So, you can either use if or use if else statements according to your requirement. We will see the use of both cases in the next part.

How to write an if statement?

Let us see the first style on how to write a simple if statement. Refer to the below image. As defined above, if the condition is true, then the statements inside it will execute. Otherwise, it will leave and go to the next case. In our example, we use the same ladder logic of start and stop. The logic written is – if the variable I_Start is on, then the variable Sys_Running turns on. If the variable I_Stop is on, then the variable Sys_Running turns off. So, as in the ladder logic, we need to latch the system running bit, because the start button is momentary. That is why, we write the logic below.

If Else Statement in SCL Language

Now, if we see an if statement written in SCL language, we use two such types. In the first case, if the start variable is on, then we write value “1” to the sys_running bit. If the start variable was not on, then the statement inside it would not execute. But here, we also need to turn it off when the stop button is pressed. So in the second case, if the stop variable is on, then we write value “0” to the sys_running bit. If the stop variable was not on, then the statement inside it would not execute. Due to this, our logic is executed properly according to our requirements. So, the step to write an if statement is – write the condition inside if keyword, use then keyword, write the statements inside it, and use end_if keyword to terminate.

How to write an if else statement?

Let us see the second style on how to write a simple if-else statement. Refer to the below image. As defined above, if the condition is true, then the statements inside it will execute. Otherwise, it will execute the other statements and go to the next case. In our example, we use the same ladder logic of start and stop. The logic written is – if the variable I_Start is on, then the variable Sys_Running turns on. If the variable I_Stop is on, then the variable Sys_Running turns off. So, as in the ladder logic, we need to latch the system running bit, because the start button is momentary. That is why, we write the logic below.

SCL Statements IF ELSE

Now, if we see an if-else statement written in SCL language, we use one such type. If the start variable is on or the sys_running bit is on and the stop variable is off, then we write value “1” to the sys_running bit. Else, we write value “0” to that same bit. So, in either case, the corresponding statements are executed. Due to this, our logic is working properly according to our requirements. So, the step to write an if-else statement is – write the condition inside if keyword, use then keyword, write the statements inside it, then use else keyword, write the statements inside it, and use end_if keyword to terminate.

In both the styles, the work done is the same. Only the way of writing differs. For this purpose, you need to understand the question first in any case, which will help you write the logic in any scenario. In the next post, we will see how to use case statements in SCL language.

Read Next:

  • Types of Expressions in the SCL Language
  • How to Configure IP Address in Rockwell PLC?
  • Complex Car Parking Logic in Electric PLC
  • PLC Bottle’s Capping with a Rotating Mechanism
  • PLC Programming for Sorting Conveyor System
Don't Miss Our Updates
Be the first to get exclusive content straight to your email.
We promise not to spam you. You can unsubscribe at any time.
Invalid email address
You've successfully subscribed !

Continue Reading

PLC Instruction List Example for Level Control of Tank
PID Controllers in Closed Loop Control Systems – PLC Basics
Timers in Codesys – Timer ON, Timer OFF, Pulse Timer
Main differences between Sinking and Sourcing Circuits
PLC Count values higher than 999
Configuration of Siemens VFD Using TIA Portal Start drive
Share This Article
Facebook Whatsapp Whatsapp LinkedIn Copy Link
Share
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Stay Connected

128.3kFollowersLike
69.1kFollowersFollow
208kSubscribersSubscribe
38kFollowersFollow

Categories

Explore More

Draw a Ladder Logic to switch ON-OFF a Bulb using a Toggle Switch ?
Siemens PLC Tia Portal – OB100 Start-up Organization Block
While Do Statement in Structured Text PLC Program
How is Data Stored in Standard Modbus Protocol?
Move, Move Bit, Move Digit – Examples of Omron PLC Programs
#11 PLC Best Practices – Instrument for Plausibility Checks
How to Troubleshoot a PLC System?
PLC Program for Blinking Lamp on 5 Seconds Interval

Keep Learning

Single-Acting Cylinder Control Operation using Proximity Sensor

Single-Acting Cylinder Control using Proximity Sensor

PLC programming for liquid mixing application code

PLC Mixing Logic in Liquids on EcoStruxure Machine Expert-Basic

Types of PLC

Types of PLC

PLC Program Backup in Siemens Tia Portal

How to Take Program Backup from Physical PLC? – Siemens PLC

PLC programming for clothes washing machine automation

LS Electric PLC Program Example: Clothes Washing System

Example of PLC Programming based on Logic Circuit

Example of PLC Programming based on Logic Circuit

Components of SCADA

Components of SCADA

Smart Drip Irrigation System Using PLC

Scheduled Daily Plant Watering PLC Program

Learn More

Asynchronous Motor Animation

Asynchronous Motor Animation

Conductivity Meter

How to Select a Conductivity Meter

AENT Module in Rockwell PLC

AENT Module in Rockwell PLC – Remote IO Adapter

Best YouTube Channels for Cyber Security

Best YouTube Channels to Learn Cyber Security

Piping Schematic for Two Solenoid Valves Double Acting

Different Types of Control Valve Actuators

Loop Diagram

PT Loop Diagram Faults

WirelessHART Principle

Wireless HART Communication Protocol Overview

Traces in TIA Portal

What is Trace Function in Tia Portal?

Follow US
All rights reserved. Reproduction in whole or in part without written permission is prohibited.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?