LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop w/ auto index tunnel - Question

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.

0 Kudos
Message 1 of 10
(4,332 Views)

Use a for loop with a conditional terminal - it will behave like you want.


___________________
Try to take over the world!
0 Kudos
Message 2 of 10
(4,319 Views)

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.

0 Kudos
Message 3 of 10
(4,312 Views)

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.

0 Kudos
Message 4 of 10
(4,309 Views)

@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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 10
(4,307 Views)

@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/ 

0 Kudos
Message 6 of 10
(4,301 Views)

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!

0 Kudos
Message 7 of 10
(4,296 Views)

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

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 8 of 10
(4,293 Views)

@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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 10
(4,289 Views)

@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. Smiley Wink

0 Kudos
Message 10 of 10
(4,280 Views)