LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting how many times a for loop is executed

Hello, I have a while loop that never stops so a sensor is continuously reading values. Inside of it, I have a condition that has to be met by the values given by the sensor. When it is met, it goes under a for loop that does a series of operations that end up outputting a string. The condition is only met 4 times, and I would like to save the 4 different strings created into an Array. However, I cannot seem to find a way to count how many times the condition is met and therefore goes through the for loop and make that the index of the array where the string is supposed to be saved or to keep expanding the array every time a string is outputted

 

Any ideas?

0 Kudos
Message 1 of 6
(5,893 Views)

You say "when the condition is met, it goes under a For Loop".  But that For Loop runs every time, and it runs for 9 iterations.

 

What "condition" are you talking about?

0 Kudos
Message 2 of 6
(5,875 Views)

Sounds like you need to learn about shift registers.

0 Kudos
Message 3 of 6
(5,829 Views)

In general, you can get the count from the count terminal of a for loop.

lc.png

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 4 of 6
(5,804 Views)

@paul_cardinale wrote:

In general, you can get the count from the count terminal of a for loop.

lc.png


NO the count terminal tells you how many times a "standard" For Loop will run before it exits.

 

The Iteration terminal actually counts how many times the loop has run.

 

In the event of a For Loop with a conditional terminal, the loop may NOT actually run the full count wired to the count terminal or the count that comes from auto indexing an array.

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 6
(5,766 Views)

The title is "Counting how many times a for loop is executed", but the question in the post is "count  how many times a condition has been met":

 

How many times a condition has been met.png

or:

How many times a condition has been met 2.png

0 Kudos
Message 6 of 6
(5,755 Views)