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: WHILE DO 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 > WHILE DO Statement in SCL Language

WHILE DO Statement in SCL Language

Learn how to use the WHILE DO statement in SCL Language for executing tasks based on conditions without limits.

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

In the earlier post, we saw how to write a for-do statement. It was used to perform a task within certain criteria and if the criteria was finished the execution was finished. The same task is performed by a while do statement, but in a different way. While a certain condition is true, the statements will be executed. Now you may think that it is similar to a for do statement, but there is a slight difference. Let us see in this post how to write a while-do statement in SCL language.

Contents
What is a while-do statement?How to write a while-do statement?

What is a while-do statement?

In the for-do statement, you had to specify two limits within which the condition will be checked and the statements will be executed. But in the while-do statements, two limits are not required. A single condition is checked, and if this condition is satisfying, then the statements will be executed in a continuous loop. When the condition goes false, it goes out of the loop and exits. So the general meaning is that – while the condition is true, execute the statements in a loop and when the condition goes false, come out of the loop.

The general syntax for this construction is –

While Condition Do

Statement;

End_for;

The meaning is – check for the condition, execute the statement and come out of the loop. Then again check the condition, execute the statement and come out of the loop. This loop will continue until the condition goes false. Once false, the loop is exited and the PLC executes other logic written.

If it is required to exit the loop in between, then mention a keyword named exit; in between. Due to this, the loop terminates without executing fully. You can also write this under an if-else condition, to come out forcefully from the loop. One thing to remember is to not execute a loop under an already existing loop; otherwise it will become infinite and the PLC will go into fault mode.

How to write a while-do statement?

Refer to the below image. The logic is – while the value of seconds is more than 0, decrement it’s value every 1 second by 1. The initial value of this tag will be 10. Once this value becomes less than 0, then the decrement will be stopped. For your understanding, I will also use the exit keyword to understand more better.

WHILE DO Statement in SCL Language

The execution flow is as follows –

  1. We have fixed or initialised the value of the secs as 10.
  2. First, the secs is initiated to 10, so that abrupt addition does not execute.
  3. So, as this value is more than 0, it jumps inside the loop where a timer instruction is first written for executing every 1 second. After every 1 second, we decrement the value by itself to 1, as shown in the 47th line.
  4. The loop is then exited through exit keyword. Then, it comes out of the overall construct and again goes back to the condition. As the value has now become 9 and still more than 0, the loop is executed once again. This goes on till the value becomes 1. The loop is executed one last time and when it becomes 0, the execution stops and the loop is exited finally.

You could have written this statement in an if-else style too. Simply replace the while statement as – if secs>0 then, remove the exit keyword and replace end_while with end_if. But, this is good for our example of simple decrement. If complex statements are required to be executed continuously in a loop, then you would have to write an if-else statement, which would make the program bulkier. In that case, a while loop statement makes a task much easier to work.

In the next post, we will see how to make use of comments in SCL language.

Read Next:

  • PLC Programming for Baking Modes
  • PLC Hoist Crane Programming Example
  • PLC Program for Password Management
  • Clothes Washing Program using PLC
  • PLC Example for Traffic Light 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

GET Command – Siemens PLC-to-PLC Communication Project
Motion Detection based Street Light: PLC Logic Solution
#2 PLC Best Practices – Track Operating Modes
PID with Practical Example
Oil and Water Separation Process using PLC Programming
PLC Program for Food Processing Industry
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

Concept of Latching in PLC
DeMorgan’s Theorems using Ladder Diagram
How to Work with Delta PLC Simulator?
Move, Move Bit, Move Digit – Examples of Omron PLC Programs
Different Types of Schneider PLC
Advanced PLC Course with Programming and Simulation
PLC Multiple Outputs Configuration
Electrical Ladder Diagram Control using Timers Example

Keep Learning

Flexible Input Output Modules

Flexible Input Output Modules

Basics of Sinking and Sourcing

Basics of Sinking and Sourcing – Automation System MCQ

Siemens PLC Programming OBs in Siemens TIA Portal

FC Function in Siemens PLC

Parking Lights PLC Program Explained with Video

Parking Lights PLC Program Explained with Video

PLC Program using Timers

PLC Timers Program

How to Prevent Ground Loops in Analog Circuits?

How to Prevent Ground Loops in Analog Circuits?

Difference Between Wifi and Industrial Wireless

Difference Between Wifi and Industrial Wireless

Ladder Logic Example of Two Motors

Ladder Logic Example of Two Motors Interlinked with another Motor

Learn More

PID-Controller-Selection

PID Controller Selection

How to Locate Faults in Cables? - Fault Analysis and Location

How to Locate Faults in Cables? – Fault Analysis & Location

What Happens When a Pump Runs Dry

What Happens When a Pump Runs Dry? How to Avoid it?

SFC Language in PLC Programming

SFC Language in PLC Programming

Phase Watcher Multiphase Flow Meter (MPFM) Procedure

Electric Circuits Objective Questions

Electric Circuits Objective Questions – Set 17

CO2 Analzer Working Principle

Infrared Non Dispersive CO2 Analyzer Working Principle

stepper motors Animation

Fundamentals of DC Motor Animation

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?