LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

While loop nested in a For loop

I have a very basic question that I couldn't find the answer to while dredging through the posts: 
When you have 2 loops, one nested within the other, does the outer loop pause it's execution while the inner loop runs?  I would assume the answer is yes from my experience with text based code, but it is unclear to me if LabVIEW follows this same convention due to its data-flow operation.  If the answer is yes, does it matter if they are For/While loops? 

In my application I have a While loop nested in a For loop.  A local variable in the For loop triggers the While loop and I would like the For loop to wait to continue it's iteration until the While loop is done, and the time it takes for the While loop to execute is not constant (can't use a wait timer).

Thanks,
Nathan
0 Kudos
Message 1 of 8
(3,284 Views)

Yes, a while loop nested in a for loop will have to run to completion before the for loop goes to the next iteration. Everything contained inside a block of code (loop, sequence frame, event structure, etc.) will have to execute before that block exits.

0 Kudos
Message 2 of 8
(3,280 Views)
Yes, a loop iteration cannot finish until all nodes contained in it have finished. The beauty of dataflow! 🙂
0 Kudos
Message 3 of 8
(3,266 Views)

I have a case as an inner while loop will not execute properly. The dataflow is not behaving as I thought it would. The inner while loop with the event structure only initializes and doesnt execute properly. I am trying to create an program that reads the data from the main loop and sends it to another loop that has an event structure that will write a new line (ie new part) into a spread sheet.

0 Kudos
Message 4 of 8
(2,748 Views)

Hi gascon,

 

attach your VI to demonstrate the problem!

 

Which events are configured in the event structure?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(2,734 Views)

My appologies. PROBLEM SOLVED! I dont mean to waste your time. The attached file named 12.27.13 is the file I intended to attach. I was trying to transmit data to a nested while loop. It was a nightmare being new to this type of programming. I tried using notifiers and a Master slave architecture but neither seemed to communicate propperly (im sure it was my doing) It tried miving the contentnts of the inner while loop to the outer, this time I initialized the contents outside the while loop. This allowed for propper data flow. it allowed for propper dataflow. 

 

The file 12.27.13 has the nested loop issue.

 

THe file "test" shows the working copy and combined while loops.

 

 

Thanks

 

Hope this helps for anyone who read in future.

Download All
0 Kudos
Message 6 of 8
(2,726 Views)

Here is the prooper file for the above 

0 Kudos
Message 7 of 8
(2,712 Views)

SInce the number of iterations for the outer while loop is known from the start, a FOR loop would be correct instead.

0 Kudos
Message 8 of 8
(2,707 Views)