Jump to content

Recommended Posts

Posted
Can someone give me a practical use of the instruction for/next. When things are slow I always try to advance my knowledge of programming instructions. I have been using it in practice programs and can't make any sense of it's use. I see it goes through its number of predetermined numbers each scan but it then scans the rest of the program and starts again without any control to stop it. Has anyone actually used it - and how.
Posted
There are many uses for this, like searching through arrays and doing math. I've created a small example showing how to loop through an array of words, looking for the number "5". This isn't very useful, but maybe it can give you some clues? I would say that for normal machine control logic there isn't much use of FOR-NEXT since machine control relies on sequences. FOR-NEXT is more of a way to crunch numbers and to avoid creating a whole sequence just to work around the whole SCAN problem. I can't remember any "simple" real-life examples right now, but what kind of programming do you normally do?
Posted
For Next creates a repeating loop of code. The code inside will repeat the specified number of times. I used it once to perform 61 compares. Instead of writing them all, I wrote one in a loop and incremented a pointer. Just be careful, because it runs that number of loops every single PLC scan. So it can be a great way to extend a PLC scan time and crash on a watchdog timer if used wrong.
Posted
Right thanks. I can see the scan time would increase and maybe fault out if you didn't extend the watchdog timer The bit I don't like is that it executes every scan - so maybe if I use it, I could put the instruction on a pointer and use it when needed - maybe? Thanks for the examples.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...