# LabVIEW

cancel
Showing results for
Did you mean:

## How Can I reset the i in the while loop to 0 after i=15 each iteration?

Hi members,

I want to ask how can I reset the i in the while loop to zero after i reach 15 in labview..

I want always to reset the i to zero after i reach 15.

your help will be highly appreciated

Message 1 of 6
(1,494 Views)

## Re: How Can I reset the i in the while loop to 0 after i=15 each iteration?

Hi Tasnim,

you cannot reset the "i" (iteration counter) in the while loop.

But you could apply simple math on the value delivered by i: when you want to count up to 15 and then start again with zero (like a sawtooth pattern) then a simple modulo operation (using Quotient&Remainder) will be the solution!

Best regards,
GerdW

using LV2016/2019/2020 on Win8.1/10+cRIO
Message 2 of 6
(1,473 Views)

## Re: How Can I reset the i in the while loop to 0 after i=15 each iteration?

@Tasnim wrote:

I want to ask how can I reset the i in the while loop to zero after i reach 15 in labview..

I want always to reset the i to zero after i reach 15.

0-15 can be done with an AND. I AND 15 will result in 0-15. On an FPGA, that will be much more efficient than a Q&R, that potentially requires multiple iterations.

On an FPGA, you'll also run into the problem that the i will reach it's max value pretty soon. You'll get that on a PC as well, but it can take a while... On and FPGA running at 40 MHz, the 31 bits become a problem after 53 seconds. IIRC, on FPGA, the i will stop at it's maximum value, on a PC it will wrap to the min value. Not sure...

I'd consider for a shift register for any code except the most trivial. Increment the value when approprieate, and use Q&R or AND to get the effect. This will be more flexible in the long run, as the behavior is decoupled from the loop counter.

Message 3 of 6
(1,448 Views)

## Re: How Can I reset the i in the while loop to 0 after i=15 each iteration?

If your loop runs extremely quickly (typically on FPGA) you might instead consider a Shift Register and a select node with equals 15 comparison.

Message 4 of 6
(1,446 Views)

## Re: How Can I reset the i in the while loop to 0 after i=15 each iteration?

I will also throw in my vote for keeping your count in a shift register.  As stated, only truly necessary if in an FPGA, but anything running a long time should use the shift register method instead of the iteration terminal.

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
Message 5 of 6
(1,393 Views)

## Re: How Can I reset the i in the while loop to 0 after i=15 each iteration?

Just in case the base courses where skipped:

Message 6 of 6
(1,256 Views)