LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to run a For Loop independently within a While Loop in LabVIEW 2013?

Solved!
Go to solution

In my program I would like to run a For loop inside of a While loop, and have them run independently, at their own execution rates.  As a test, I wrote a simple VI with a While loop with 1 second timing, and into this I inserted a For loop with 3 second timing.  I created indicators for both iteration terminals.  Upon running the VI, I found the While loop waits for the For loop to run N times before the While loop executes again.  I also found that sometimes the first iteration of the For loop will end at 1 second rather than 3 seconds, and the STOP button to terminate execution of the While loop does not always work.

0 Kudos
Message 1 of 5
(2,594 Views)
Solution
Accepted by ksinks
That is expected behavior. LabVIEW is s DATAFLOW language. If you want the loops to be independent, there can't be data forcing a dependency so use separate loops.
Message 2 of 5
(2,589 Views)

This is contrary to any programming language loop structure.  Even more so in a data flow language like LabVIEW.  A while loop cannot begin a new iteration until all the code in the loop has executed.  Period no way around it.

 

You could run the loops in parallel and use a synchronization method to control relative timing.  Have you gone through the "Getting Started exercizes?  They might help you understand what happens in a LabVIEW vi


"Should be" isn't "Is" -Jay
Message 3 of 5
(2,587 Views)

Thanks, how would you synchronize the loops?  I have gone through the Getting Started exercises and manual.

0 Kudos
Message 4 of 5
(2,563 Views)

@ksinks wrote:

Thanks, how would you synchronize the loops?  I have gone through the Getting Started exercises and manual.


Why would synchronization matter? Did you want them to run independantly at their own speed or not?

Regardless, there's a synchronization pallette with functions for this, as Occurance.

Other solutions include a common loop counter and a case structure executing every X'th iteration, or having the faster loop send a queue or event every X'th loop that controls the slower loop.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 5
(2,529 Views)