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
  • Request
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
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
  • Request
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

Comparison of Control Loops – Open, Closed, Cascade, Feedforward, Ratio
PLC Ladder Program for Automatic Car Wash using Siemens TIA Portal
Intrinsically Safe Barriers Questions and Answers
Difference between Timer and Counter – PLC Basics
Single-Acting Cylinder Control using Proximity Sensor
Advanced PLC Conveyor Control: Forward and Reverse Rotation
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
210kSubscribersSubscribe
38kFollowersFollow

Categories

Explore More

PLC Pump Control: 10 seconds ON & 20 seconds OFF
Quiz: Identifying I/O Examples in PLC Systems
3 Phase Motor Control using PLC Ladder Logic
Daily Alarm PLC Program using Real-Time Clock
PLC Timer Instructions
Comparator in PLC Programming
Connecting Blocks in Functional Block Diagram – Studio 5000
Count the Number of Cartons in a Storage Area PLC Logic

Keep Learning

PLC Counter Example for Bank

PLC Program for Bank Counter Application

Industrial Automation Cold and Hot Standby

Difference between Cold Standby and Hot Standby

Types of PLC

#14 PLC Best Practices – Restrict Third-party Data Interfaces

PLC to Start or Stop 3 Machines using 1 Switch Program

PLC to Start or Stop 3 Machines using 1 Switch Program

Omron PLC real-time clock street lighting program

Automatic Highway Lights Program using RTC in Omron PLC

PLC Control Panel

Inside the PLC Control Panel: How Much Do You Know?

PLC Engineers Interview Questions

PLC SCADA Engineers Interview Questions and Answers

PLC Count values higher than 999

PLC Count values higher than 999

Learn More

What is PLC Redundancy

What is PLC Redundancy?

Digital Electronics MCQ

Digital Integrated Circuits Objective Questions – Part 3

Laws of Thermocouples

What we need to Know before Tune a PID Controller

What we need to Know before Tune a PID Controller ?

PLC Examples for calling functions in SCL

How to Insert Block Calls in SCL Language?

Mechanical Torsion Meter Principle

Mechanical Torsion Meter Principle

Electro Magnetic Flow Meter Animation

Magnetic Flow Meter Animation

D’Arsonval Movement

D’Arsonval Movement

Menu

  • About
  • Privacy Policy
  • Copyright

Quick Links

  • Learn PLC
  • Helping Hand
  • Part Time Job

YouTube Subscribe

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?