News:

  • April 29, 2026, 09:33:04 AM

Login with username, password and session length

Author Topic: "Freezing" a FOR/NEXT Loop  (Read 10614 times)

Bolt

  • Hero Member
  • *****
  • Posts: 594
"Freezing" a FOR/NEXT Loop
« on: November 26, 2024, 02:12:46 PM »
Is there a way to "freeze" a FOR/NEXT loop? Say I have a loop monitoring some bits. If a bit becomes TRUE, I'd like to keep the pointer value where it is, end the loop, and let the rest of the PLC's logic proceed as normal. It's not quite a BREAK, as next scan I'd like the loop to continue with it's previous pointer value. Is this even a thing?

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: "Freezing" a FOR/NEXT Loop
« Reply #1 on: November 26, 2024, 02:23:21 PM »
There is no "enable" leg on a FOR/NEXT loop.

What you can do, is emulate a FOR/NEXT using WHILE/WEND where you can conditionally terminate the loop with conditions other than Count < Preset (e.g. EnableLoop AND Count < Preset)

Bolt

  • Hero Member
  • *****
  • Posts: 594
Re: "Freezing" a FOR/NEXT Loop
« Reply #2 on: November 26, 2024, 02:36:40 PM »
Ah, I hadn't thought of using WHILE/WEND here. I am considering doing a COPY Pointer to Holding and BREAK, then at the start of the loop IF Holding>0, COPY Holding to Pointer. That should work I think.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3806
    • Host Engineering
Re: "Freezing" a FOR/NEXT Loop
« Reply #3 on: November 26, 2024, 03:50:34 PM »
I forgot...
FOR/NEXT behavior is Count <= Preset
;D

Bolt

  • Hero Member
  • *****
  • Posts: 594
Re: "Freezing" a FOR/NEXT Loop
« Reply #4 on: November 26, 2024, 03:59:58 PM »
True, but no big deal here. For my application today it worked to COPY Pointer Count to Holding, and BREAK. At the top of the loop I COPY Holding back to Count so it picks up where it left off until I reset the Holding.