LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to restart a for loop?

Solved!
Go to solution

Hi all,

 

I am using a for loop to get a pair of data from a 5000 x 2 array. The pair of data will change every second. However, after a period of time, I want the for loop to repeat, which means the pair of data should go back to row 1 of the 5000x2 array.

 

Can someone teach me how to do it?

 

Thank you and have a nice day.

 

VanessaWen

0 Kudos
Message 1 of 12
(6,887 Views)
Solution
Accepted by topic author VanessaWen

Hi Vanessa,

 

- when the number of iterations of your loop is NOT known when the loop starts you should use a WHILE loop!

- when you want to index arbitrary elements from your array(s) you should NOT use autoindexing but IndexArray!

- when you want to manipulate the "loop index" (aka use your own index) you should use a shift register holding your own index. Now you will be able to manipulate that index in any way you like…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(6,870 Views)

Adding a bit, if you want your For loop to repeat, put it into another loop.

 

Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice
For he does not know what will happen; So who can tell him when it will occur? Eccl. 8:7

0 Kudos
Message 3 of 12
(6,837 Views)

Hi GerdW,

 

Thanks for suggesting a while loop. However, I do not understand the index part. Right now my goal is to extract different pairs of data from a 5000x2 array. I thought index array is for us to extract out the data in an array? After my while loop has finish extracting the 5000th row data, I want to extract the data from the first row and repeat the whole process again. This is an infinite data extraction loop until I want to stop it. 

 

Is it possible?

 

A million thanks!

 

Regards,

VanessaWen

0 Kudos
Message 4 of 12
(6,827 Views)

Hi Vanessa,

 

yes, it's possible. Use your own index counter…

 

Hint: Using Quotient&Remainder will do a lot of the work!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 12
(6,811 Views)

@VanessaWen wrote:

Is it possible?


Yes.  You will want to keep your index in a shift register and increment it with each loop.  After the increment, use Quotient & Remainder to divide the index by the array size.  You will just want to keep the remainder.


GCentral
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 6 of 12
(6,809 Views)

Hi GerdW,

 

I have tried to modify my code. Now it works. However, everytime when the loop is going to restart, the 1st row of data can't be shown as the index "1" comes in slower than the clock rate. Can you suggest any solution?

 

By the way, number 5 indicates 5 rows of data. After 5 rowss of data are used, the loop should go back to 1st row of data.

 

Thanks!

 

VanessaWen

0 Kudos
Message 7 of 12
(6,794 Views)

Well that would be the race condition caused by you mis-using a local variable and using a case structure where a Quotient and Remainder would be prefered

 

Why is Numeric is a DBL? Why is numeric is an indicator? Why is it on a Shift register?

Capture.PNG


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 12
(6,772 Views)

Jeff·Þ·Bohrer wrote: Why is it on a Shift register?

There's nothing wrong with it being in a shift register.  I avoid using the "i" terminal just because it maxes out very quickly when dealing with FPGA.  So you have to do it like this.


GCentral
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 12
(6,765 Views)
Solution
Accepted by topic author VanessaWen

@crossrulz wrote:

Jeff·Þ·Bohrer wrote: Why is it on a Shift register?

There's nothing wrong with it being in a shift register.  I avoid using the "i" terminal just because it maxes out very quickly when dealing with FPGA.  So you have to do it like this.


About every 68 years with that loop.  Thats isn't too often and I'll be unavailable when it stops workingSmiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 12
(6,756 Views)