LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I exit a FOR loop before it has completed its iterations?

Or is there a way to easily slave a while loop to an array input? I essentially need to search an array for a specific entry. Non of the built in VI's will search the array the way I need to do it. I tried wiring the array to a while loop and searching each element, but if the match is never found, the while loop never returns. Is there a setting on a while loop to force it to return if an input array completes?

The For loop will work, but it forces me to step through the entire array each time and I have to play games to ignore values after I have found and set the one I need.

Thanks for any help

Chris
0 Kudos
Message 1 of 4
(3,918 Views)
Hi Chris,
you can't stop a for loop before it has completed its iterations.
A quick tip:
- determine the array size before entering the while loop
- force the while loop to stop if the iteration has overtaken the size minus 1 (match not found)

Good luck,
Alberto
0 Kudos
Message 2 of 4
(3,909 Views)
A for loop always executes the number of iterations. A while loop will terminate whenever the condition is met that you specify. If you wired a boolean constant to the termination terminal, then tha'ts why it never stops. Instead, wire the result of some comparison to the termination terminal. The termination terminal can be set to either terminate when true or continue with true. Just clicking on the terminal with the "finger" selector will change this or right click on ther terminal. You can also enable auto-indexing of arrays just like a for loop. Where the array enters the while loop, right click on the input terminal and select Enable Indexing.
0 Kudos
Message 3 of 4
(3,908 Views)
Hello –

I am attaching a very simple example program to show what Alberto and Dennis explained (or at least what I understood their approach would be, please apologize if I misunderstood).

Another option is to use the Search 1D Array function, located in the Functions >> All Functions >> Array subpalette.

Hope this helps.

SVences
Applications Engineer
National Instruments
0 Kudos
Message 4 of 4
(3,860 Views)