LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

stop for loop

Hi,
I'm using for loop for let's say i=40
can i stop the loop in the middle (when i=20) and contino the program from there?
Regards,
Etay
0 Kudos
Message 1 of 8
(4,292 Views)

Its not possible to do that in LabVIEW

The FOR loop has to finish its set number of iterations before stopping

 

Message 2 of 8
(4,273 Views)
You must use a while loop if the loop must be stopped before its set number of iterations !
0 Kudos
Message 3 of 8
(4,265 Views)
For now that is.  to answer your question, you can put the 'meat' of your code within a case structure, and 'skip' it if you have an undesireable condition.  Or you can create a while loop with multiple exit scenerios including your undesireable condition(s) or completion of processing your data structures.  The choice is yours. 

Paul
0 Kudos
Message 4 of 8
(4,256 Views)
 
In this case the loop can be stopped before the loop count
If the loop count is 20 and the array size is 10 then the loop will iterate for 10 times only
If the loop count is 10 and the array size is 20 then also the loop will iterate for 10 times only
So which ever is less the loop will iterate that many times
0 Kudos
Message 5 of 8
(4,254 Views)

Hi Kumar,

Can you attach the screenshot once again ?

- Partha ( CLD until Oct 2027 🙂 )
0 Kudos
Message 6 of 8
(4,248 Views)
 
On Parthabe's request reattaching the image
In this case the loop can be stopped before the loop count
If the loop count is 20 and the array size is 10 then the loop will iterate for 10 times only
If the loop count is 10 and the array size is 20 then also the loop will iterate for 10 times only
So which ever is less the loop will iterate that many times
Still not able to catch the image.???????? i can mail you if you could post your mail id
0 Kudos
Message 7 of 8
(4,243 Views)

You can also program the logic into it. I've used this a few times. Just put everything in the loop inside a case structure, then you can do some boolean operation that you want to use to stop the loop, wire this to a shift register and use it on the next iteration. In the true case, just wire everything through so nothing happens once the condition is met. The loop is still running, but it isn't doing anything and will finish very quickly.

I also added a shift register for the iterator in this example so you could obtain it after the "break" condition occurred.

Message Edited by Marc A on 06-13-2007 09:02 AM

0 Kudos
Message 8 of 8
(4,225 Views)