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

Peripheral Inputs and Outputs in Siemens PLC
Shutdown Motors in Timed Operation PLC Program
Tank Filling and Emptying using Intouch Scada Script
Automate Batch Mixing with Repeated Cycles in Omron PLC
Readings Mismatch between Field & Control Room ? Why
Start the Counting from a Preset Value 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
210kSubscribersSubscribe
38kFollowersFollow

Categories

Explore More

Difference between DCS & PLC Systems
What is Distributed IO? – Decentralized Peripherals in PLC
Upload Option Disabled in Siemens PLC
FC Function in Siemens PLC
Steps in PLC System Design
What is an Instruction List? – PLC Programming
Types of Interrupt OB in Siemens Tia Portal
Sorting & Distribution Line PLC Programming – Advanced Logic

Keep Learning

PLC Pump Control

PLC Pump Control: 10 seconds ON & 20 seconds OFF

Difference between Power Cables and Signal Cables

Difference between Power Cables and Signal Cables

How to Select the Right Encoder for Your Machine

How to Select the Right Encoder for Your Machine?

PLC Program for Control Valve Scaling

PLC Program for Control Valve Scaling

Architecture of Allen Bradley PLC

Architecture of Allen Bradley PLC

PLC railway crossing program

Automatic Railway Crossing Gate Control PLC Program

Types of Cables used in Industrial Automation

Types of Cables used in Industrial Automation

Sequential Operation of Output Bits using Two Push buttons

Sequential Operation of Output Bits using Two Push buttons

Learn More

Read Temperature in PLC

PLC Program to Read Temperature in PLC

SC connector

What is a Network Connector? – Types of Connectors

Alarm Management Practices

Control Room Alarm Management Practices

SIS Fault Tolerance

SIS Hardware Fault Tolerance – Methods to Overcome HFT issues

Control Valve Calibration

How-to do Control Valve Calibration?

Types of Limit Switches

Types of Limit Switches – Principle, Advantages, Disadvantages

Process Override Switch

What is Process Override Switch (POS)?

Remote Seal Pressure Transmitter Temperature

Importance of Temperature in Remote Seal Pressure Transmitter

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?