The fear of FOR TO and WHILE loops

FOR loops are an indispensable tool to solve tasks that involve lots of similar data.
That 100 ladder rungs use marginally less cycle time than a FOR loop is irrelevant. Also, that Bubba better understands 100 rungs than a FOR loop .... really ?
If Bubba cannot grasp what a simple FOR loop does, then he should stay away from PLC programs.

WHILE loops are riskier than FOR loops since the exit from the loop is conditional, as opposed to the fixed number of passes through a FOR loop. Manipulating the FOR loop counter should be avoided for the same reason.

I use FOR loops regularly. I have never ever programmed a WHILE loop.
 
WHILE loops are riskier than FOR loops since the exit from the loop is conditional, as opposed to the fixed number of passes through a FOR loop.

While riskier, it's common in other languages to include a timer in the While condition or inside it with the instruction to break the loop should it overrun.
 
While riskier, it's common in other languages to include a timer in the While condition or inside it with the instruction to break the loop should it overrun.


But then timer should be less than 200ms or what ever watchdog time is configured to PLC.


Still setting timer too close of watchtdog time can fault PLC, since time is added every scan and time on last scan is still less than watchdog but one scan after that is over watchdog time.
 
Last edited:

Similar Topics

Good Afternoon , My biggest fear came true. I lost a USB stick that had my RS Logix 5000 activation on it . What is the best way to get...
Replies
8
Views
7,109
Hello The plant is running and there is no shutdown nowadays therefore I can add 1734- AENTR and its card while PLC is in Run? I do not wanna...
Replies
1
Views
113
I have an issue with Power Flex 525 during running processing, the VFD stopped suddenly while the PLC and VFD connection ok, VFD does not have any...
Replies
1
Views
89
Hello! When trying to load the hardware configuration I get error 0050-133 2 2458, check the diagnostic buffer. When checking the buffer, it says...
Replies
4
Views
128
Can the following be made into a SINGLE Ladder so it could be incorporated with more ladder code and then made into an AOI? I have been trying...
Replies
26
Views
1,103
Back
Top Bottom