LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

For Loop does not run for an input of N times

This question is so bizarre, I've never seen anything like it. 

 

I have a for loop, I input a number done by a calculation of inputs. I convert that calculation into an integer, and wire that to the N input of the for loop. However, when I ran my program, it didn't execute the number of times the calculation was meant to give. 

 

I connected an indicator to the wire attaching the integer conversion to the N input. I also put an indicator on the inside of the for loop, connected it to N.

 

I ran the program. The indicator OUTSIDE the for loop, which DIRECTLY wires to N, has the right number. However, the indicator of N that shows how many times the loop is running randomly is "4", consistently. No matter how I change the parameters. I have no idea why this would be. 

 

Has anyone else every experienced this problem? Any suggestions would be greatly appreciated.

 

Update: I connected a numeric constant to N, instead of the math, to see if anything would change. Nothing does. So even if I wire a numeric constant to the loop, N's indicator inside the for loop always is 4. Now, the for loop is inside a larger while loop, which is set to only run once. Essentially, its sole purpose is just to have a built-in stop on a more complex program, so that it only runs once. Since it only runs once, I don't see how it could be limiting the number of times a for loop inside it will run, but figured it was worth noting. 

 

Also note: the N input wire is constant for the entire program.

0 Kudos
Message 1 of 8
(4,990 Views)

It would help if you attached a VI that demonstrated what you are seeing.

 

Do you have any arrays going into the For Loop?

Is that array's tunnel set for Auto-indexing?

 

A For Loop runs for either the number of times you have wired into the N terminal, or the number of elements you have in any array wired in with auto-indexing tunnels.  Which ever is the smallest number.

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

It's not an array, sadly, though that definitely would've been the solution if that were the case!

 

Into the N input of the for loop is a simple calculation of subtraction of two input parameters, and then dividing that by another input parameter afterwards. The output of that calculation is converted into an integer, which is in the realm of 100 or up depending on user inputs. I created an indicator on the output of the division, which shows this number on the UI. The division's output is connect straight to N, so it should agree with the number on the indicator. 

 

However, the loop consistently only runs 4 times regardless of the inputs, which is in constant disagreement with the indicator of the value connected to the for loop's N. 

0 Kudos
Message 3 of 8
(4,977 Views)

Solution: The loop ran the correct number to times when I converted the for loop to a while loop. 

0 Kudos
Message 4 of 8
(4,951 Views)

Hi Jane,

 

you failed two more times to provide an example VI.

And converting from For to a While loop usually is not the proposed solution...

Best regards,
GerdW


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

@JaneDoe1234 wrote:

Into the N input of the for loop is a simple calculation of subtraction of two input parameters, and then dividing that by another input parameter afterwards. The output of that calculation is converted into an integer, which is in the realm of 100 or up depending on user inputs. I created an indicator on the output of the division, which shows this number on the UI. The division's output is connect straight to N, so it should agree with the number on the indicator. 

 

However, the loop consistently only runs 4 times regardless of the inputs, which is in constant disagreement with the indicator of the value connected to the for loop's N. 


As others have already hinted, verbal descriptions are too ambiguous to help. We think graphically and actually seeing you VI is the only way that we can help you.

 

I won't even try to attempt to suggest a solution before you do so. There are many possible reasons that can explain what you are seeing.  I am 100% sure it is that the PEBKAC. FOR loops have existed since version 1.0 and don't have any bugs.

0 Kudos
Message 6 of 8
(4,927 Views)

If you also connect an array that auto-indexes, the amount of loops will be the lowest of the array size and the number connected to N.

But since you haven't posted any VI it's a guess ...

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 7 of 8
(4,841 Views)

If conversion to a while loops works, it seems to me the loop condition might be connected in the for loop.

 


@JaneDoe1234 wrote:

However, the indicator of N that shows how many times the loop is running randomly is "4", consistently.


"i" shows how many times the loop is running. "N" shows how many times the loop will run if not stopped by the loop condition.

 

If only we had an image or VI...

0 Kudos
Message 8 of 8
(4,822 Views)