# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## I want to create a counter for each time my loop finishes

Hi 🙂 My program runs for a given time and writes data to a file. After the time has been reached the program goes into a "pause" loop, where nothing happens, and then begins running again. I want to be able to decide have many times it runs the program. I know I can use a for loop, but I want to try to use some sort of counter as you can see in the attachment file below. After the counter has reached the given value, then the entire program stops.

Thanks!

Message 1 of 5
(3,009 Views)
Solution
Accepted by kristaje

## Re: I want to create a counter for each time my loop finishes

Why don't you do what you are already showing with a shift register, increment, and comparison in the while loop?

(You should make those values integers rather than double since you are just counting.  You can run into problems when when comparing floating point numbers (doubles) for equality.)

Message 2 of 5
(3,004 Views)
Solution
Accepted by kristaje

## Re: I want to create a counter for each time my loop finishes

Your counter belongs in the state machine loop.  You might want to add a state to increment and check to see if you are complete.

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 3 of 5
(3,003 Views)

## Re: I want to create a counter for each time my loop finishes

Hi! Thank you for the tips. I still can't manage to figure out the solution. I added the loop counter as a new state. When we get to "Count", the value should begin at 0 and add 1 for each time it executes. Right now it adds the same value as my "Number of intervals" control is set to. I want it to return back to "Collect data" after adding "1".

Thank you

Message 4 of 5
(2,914 Views)

## Re: I want to create a counter for each time my loop finishes

There is no reason to have the loop inside of the "Count" case.  Your "loop count" should be a shift register on the main loop.

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 5
(2,907 Views)