Share this

Loop syntax in PLC programming

2026-04-06 05:24:05 · · #1

All computer programming languages ​​have loop functionality.

PLCs are also included.

Therefore, it certainly has a loop function.

Regardless of the CPU or programming language, all have loop syntax for implementing loops. However, in many cases, language support for loops is not ideal. Pointers, indirect addressing, and other methods are usually required. Therefore, loops are considered a relatively difficult topic in PLC programming.

I know that some people care a lot about mastering loop programming syntax, while others are very troubled by their inability to handle loops.

Let's analyze this problem today.

First, let's look at the significance of loop programming methods. Several aspects:

1. Improve CPU efficiency;

2. Reduce the amount of program code and decrease memory usage.

3. Reduce the workload when programming.

First, regarding point 1, using loop statements like FOR...NEXT doesn't actually improve CPU workload much. Looping 100 times is no different from writing 100 lines of code. Even with a very large number of loop cycles, you still need to be careful about OB1 loop timing out.

Regarding point 2, reducing the amount of code requires a sufficient number of loop cycles. If there are only 5 objects or fewer, carefully preparing input and output interfaces for loops will ultimately increase the amount of code.

Regarding point 3, the workload and difficulty of programming must be considered comprehensively. If the programming tool supports data copying with office software, the program code can be prepared in the office software first using data processing techniques, and then directly used in the PLC environment. This may sometimes reduce the workload and be faster.

In industrial automation systems, the amount of data from devices is typically small. For example, a medium-sized control system might have 100 motors, which is considered quite a lot. What's worth programming in a loop is usually a sequence of devices of the same type. More than five such devices are rare.

If a cyclic programming approach is to be designed, the I/O layout must be carefully considered from the outset. For example, if the input signals are arranged in the order X.0, X.1, X.2, X.3, X.4, the output signals must also be arranged in the same order.

This requires prior communication with the electrical drawing designers and coordination with the panel installers. These practices do not conform to the principles of standardized modular design.

In particular, if a point in one of the modules suddenly fails during operation, it becomes impossible to move that point to another address. This is quite troublesome.

Looking back on my PLC programming experience over the past decade, I've used loop programming very rarely. One instance that stands out is processing warehouse data, where loops were used. However, due to the large loop size, although I initially implemented it using loop statements, I later found that it caused excessively long CPU cycle times. Since there were no real-time requirements, I eventually switched to an asynchronous loop, utilizing the cycle time of OB1.

Therefore, my principle regarding loop syntax is to use loops as little as possible. Avoid using loops whenever possible.


Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964). We apologize for any inconvenience.

Read next

CATDOLL 128CM Ava (TPE Body with Soft Silicone Head)

Height: 128cm Weight: 19kg Shoulder Width: 30cm Bust/Waist/Hip: 57/52/63cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm Anal...

Articles 2026-02-22