09-12-2012 07:32 AM - edited 09-12-2012 07:33 AM
Question, I have a 1D array of data being used as an auto index tunnel into a while loop. I need to search the array and terminate the loop on the first instance of a dataset I find, which I can do with a bool wired to stop. But my question is, will the loop self terminate after indexing through the complete list of array entries or do I need to stop it based on the array size?
Thanks.
09-12-2012 07:35 AM
Use a for loop with a conditional terminal - it will behave like you want.
09-12-2012 07:46 AM - edited 09-12-2012 07:46 AM
How do you break a for loop early then? This is why I used a while loop because it has a stop terminal which a for loop doesn't.
Thanks.
09-12-2012 07:49 AM
In terms of an answer to your question regarding the self-termination of the while loop, the while loop will not self-terminate after getting to the last index. The loop will continue to run, since the ending of the while loop is strictly controlled by the conditional terminal, not by any autoindexing (unlike the for-loop).
I agree that the for-loop conditional terminal is a better alternative, assuming you have a version of LabVIEW that has this.
09-12-2012 07:51 AM
@QRP wrote:
How do you break a for loop early then? This is why I used a while loop because it has a stop terminal which a for loop doesn't.
Thanks.
Right click on the FOR loop and select "Conditional Terminal". This was introduced in LabVIEW 8.5. So as long as you have a newer version than that, its there.
09-12-2012
07:52 AM
- last edited on
08-12-2025
05:07 PM
by
Content Cleaner
@QRP wrote:
How do you break a for loop early then? This is why I used a while loop because it has a stop terminal which a for loop doesn't.
Thanks.
I posted my response while you were writing yours. As I noted, you need a version of LabVIEW that has a for-loop that supports a conditional terminal. If you do (I think it was added in 8.5), you can add it as described in the LabVIEW Help: http://zone.ni.com/reference/en-XX/help/371361G-01/lvhowto/add_cond_to_for_loop/
09-12-2012 07:58 AM
Got it, I'm using V11 😃 I assume the loop will self terminate after indexing the array or if the conditional stop is true, is this correct?
Thanks so much!
09-12-2012 08:01 AM
Since searching arrays for patterns is common to programming tasks (string is also an array!), you might find some ready-to-go algorithm for your task if doing a little search in the internet. They might outperform a self-written solution (have to benchmark individually though....).
Norbert
09-12-2012 08:07 AM
@QRP wrote:
I assume the loop will self terminate after indexing the array or if the conditional stop is true, is this correct?
That is correct.
09-12-2012
08:41 AM
- last edited on
08-12-2025
05:08 PM
by
Content Cleaner
@QRP wrote:
Got it, I'm using V11 😃 I assume the loop will self terminate after indexing the array or if the conditional stop is true, is this correct?
Thanks so much!
From the documentation:
You can add a conditional terminal to configure a For Loop to stop when a Boolean condition or an error occurs. A For Loop with a conditional terminal executes until the condition occurs or until all iterations complete, whichever happens first. To add a conditional terminal to a For Loop, right-click the For Loop border and select Conditional Terminal from the shortcut menu. You must wire the conditional terminal and either wire the count terminal or auto-index an input array for the loop to execute and for the VI to run.
Please take the time to read the Help. ![]()