For Next loop

Why would anyone in his right mind write PLC code like that?
Good question. Another good question is why would anyone try to turn on an Output inside a For-Next loop?
 
Milk a wha?

o_Oo_O
If you use JMP to jump out of the For Next loop until the timer expires, then it will allow pausing as long as desired before completing the NEXT. Also CJ and SCJ jumps around the FOR-NEXT, and STOP and FEND will end the loop early if needed.

So your argument is that if you deliberately circumvent the designed purpose of the FOR LOOP and jump out of the FOR LOOP, it invalidates the statement that the point of the FOR LOOP is to execute the code within the FOR LOOP all within one single scan? Really? Is that really what you are going with? And you did realize that you are in fact implying that you need to JUMP OUT OF the instruction in question to achieve said behavior?! Does your example reflect good programming practice? Does it achieve a practical purpose that otherwise could not be achieved through more traditional means?o_O
 
Does it achieve a practical purpose that otherwise could not be achieved through more traditional means?
No, it does not. I am merly pointing out that there is a way to do it if you really WANT to do it. Just as the original poster asked why his Outputs INSIDE THE LOOP were not going on, as if putting them inside the For-Next loop made any logical sense! I figure that an illogical question deserves an illogical answer.

As for why he did it, I guess it was to simply to find out what happens.
My program was purely for educational purposes.
 
Last edited:
This thread is a great example of why to stay away from For/Next loops in ladder :)

I'd also like to add that not all PLCs process these loops in the same way either which further adds to the fun. I would just use a variable index method and avoid them.
 
I (personaly) think Lancie1 has 100% right . Jumping (sometimes) out from a loop is not only theorie but also practical ... see my RADIXSORT implementation !

Sometimes depending on how "big" a loop is , you must "break" the loop ... (me thinks).


Synchronous vs. asynchronous ... this is the question here ( me thinks!) .
🍺
 
Last edited:
Why would anyone in his right mind write PLC code like that? Other than to win the prize for 'most difficult to follow' or 'look how clever I am' code.

If you (for example) have to sort 2000 DINT you must break the "loop" , if you have to sort 20 DINT you don't need to break it ...

All is either relative ...or ...DOGMATIC ! It depends on ... what you are currently doing

;)
 
This thread is a great example of why to stay away from For/Next loops in ladder :)

Then you wouldn't like the last one I did that had three of them nested ;)

They serve their purpose....In my case I have to translate recipes that have colors stored in them for mixing and 16 simultaneous recipes (mixing vessels) that have 8 colors each that have to find those colors in 40 storage containers, makes nested FOR-NEXT very useable.

As for the JMP/Break, I do that also...once the color is found no sense in searching anymore. Although I hate JMP instructions so I just make the FOR loop index = Upper End which terminates the FOR loop for me.
 
I really love (conditional-)JMP instructions ! They make the ...?... DIFFERENCE !
 
Last edited:

Similar Topics

Hello All, HMI application I'm using is GE's HMI/SCada Cimplicity. Im writing a basic program in the script to do as follows. When the operator...
Replies
33
Views
5,687
Hello All, I read so many posts where individuals utilize the practice of for-next loops. And I was hoping to find some example code, so that I...
Replies
5
Views
6,201
N
In a processor like the MicroLogix 1500 which does not have a built-in FOR..NEXT loop instruction (I've seen some web sites that indicate that...
Replies
26
Views
28,628
New2PLCs
N
I've got this start screen where the user has to enter their username and password. The username and password feature works fine. However, I want...
Replies
7
Views
1,443
Anyone know what the little green triangle on SCREEN 3 means ? See picture Thanks
Replies
2
Views
459
Back
Top Bottom