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

FOR DO Statement in SCL Language

Learn how to use the FOR DO Statement in SCL Language, a powerful tool for executing repetitive tasks with ease.

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

In the previous post, we saw how to write a case statement. In this post, we will see one of the most powerful statements in SCL language – for do statement. There are many repetitive tasks which need to be done in a PLC program. For this purpose, instead of writing statements multiple times, you can use for-do statements, where a repetitive task is performed more easily and in a very less code size. This helps the programmer to easily troubleshoot a system. Let us see what this statement is further in the post.

Contents
What is a For Loop statement?How to write a For-Do statement?

What is a For Loop statement?

A for loop statement is a construct which is used to perform a function when it is present between a defined condition. Once the condition goes false, the execution stops. The statement checks for a value between two set values (one initial and one final). It starts with an initial value and goes on incrementing or decrementing till the final value is reached. After that, it leaves the loop and goes on to execute next statements. The general syntax for this style is as below:

For variable := initial value To final value By Value Do

Statement;

End_for;

The meaning is – the initial value is moved to the variable, the statement executes and ends. When the loop is exited and occurs again, the variable is automatically incremented or decremented by the value mentioned (it is optional; if not mentioned, then increment or decrement automatically happens by 1). Then again, the statement is executed and ends. The loop goes on executing as the variable is added or subtracted on every loop exit, until the final value is reached. Once reached, the loop stops executing.

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 For-Do statement?

Refer to the below image. The logic is – we need to add five values and store it in a destination. For this, the destination tag is sum, the tag where the values are stored for addition is item, which is an array of five elements, each having it’s own value. The tag index is used as a pointer to the item array element.

FOR DO Statement in SCL Language

The execution flow is as follows –

  1. We have fixed the five values of the item as 2,4,6,77,32.
  2. First, the sum is initiated to 0, so that abrupt addition does not execute.
  3. Then, the index is initiated to 0, from the condition written as 0 to 4, where 0 is moved to the index tag. So, the statement will be executed as reflecting the following – 0 := 0+2; which brings the answer as 2 (sum := sum+item[0]).
  4. The loop ends and moves again to the condition, where the value of index is now 1. So, the statement will execute as reflecting the following – 2 := 2+4; which brings the answer as 6 (2 is derived from the previous result and 4 is derived from the set value we have given; (sum := sum+item[1]).
  5. It then goes on adding till the value of index is 4 (sum := sum+item[14). Once the statement has been executed, the loop exits and stops executing. So, we get the final answer as a sum := =2+4+6+77+32, which is equal to 121.

The value of the index is incremented automatically by the PLC CPU scan time on each loop ending. It has nothing to be written separately by a programmer as shown. You could have also written this statement as:

sum := item[0] + item[1] + item[2] + item[3] + item[4] ;

But, this is good for our example of simple addition. 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 for loop statement makes a task much easier to work.

In the next post, we will see how to use a while loop statement in SCL language.

Read Next:

  • PLC Programming for Baking Modes
  • PLC Hoist Crane Programming Example
  • PLC Program for Password Management
  • PLC Program for Train Detection and Gate Operation
  • Structured Text in PLC: Parking Information Systems
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

Interconnection between PLC, MCC, LCP & Pumps – Video
PLC Automatic Pedal Switch for Speed Control
Structured Text PLC Program for Measuring Event Duration
Global Acknowledgment Instruction in Safety PLC
Difference Between CompactLogix and ControlLogix
Shift Bit Register in PLC
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

Motor Starter Logic using Siemens PLC Tia Portal
Developing PLC Logic for Water Pumping and Chemical Addition
Wiring in a PLC Control Panel
Configuration of Input and Output Tags in Siemens Scada and PLC
#2 PLC Best Practices – Track Operating Modes
I&C Engineer Roles & Responsibilities – Instrumentation Design
Schneider Electric PLC Timer Problem: Vacuum Cleaner
Free Allen Bradley PLC Ladder Logic Training Course

Keep Learning

PLC program for VFD Drive Multiple Speeds

Drive Multiple Speeds with Different Reference using PLC

How to Create Faceplate in FactoryTalk View Studio

How to Create Faceplate in FactoryTalk View Studio?

PLC Emergency Stop Example Program

PLC Emergency Stop Example Program

Example of Controlling the PLC Output using Push Buttons

Example of Controlling the PLC Output using Push Buttons

Open PLC Software

Open Source PLC and SCADA Software

Redundant Power Supply

How Does Redundant Power Supply Work?

Automatic Lamp Control in Storage Facility

PLC Program for Automatic Lamp Control in Storage Facility

TON Timer in RSlogix

Why is RTO used in the Place of TON Timer?

Learn More

Electric Motor Actuators

What is Motor Actuator ?

Overview of Tank Gauging Technologies

Transformers Interview Questions & Answers

Transformers Interview Questions & Answers

Types of Limit Switches

Types of Limit Switches – Principle, Advantages, Disadvantages

Types of Calibration

Types of Calibration

baffle-and-nozzle assembly

Pneumatic Sensing Elements

Types of Control Valves Noise

Types of Control Valves Noise

Poppet vs Spool Valves

Why Valve Type Matters ? Poppet vs Spool Valves

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?