03-04-2015 12:37 PM
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.
Solved! Go to Solution.
03-04-2015 12:43 PM
03-04-2015 12:47 PM
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
03-04-2015 02:21 PM
Thanks, how would you synchronize the loops? I have gone through the Getting Started exercises and manual.
03-05-2015 05:36 AM - edited 03-05-2015 05:38 AM
@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