04-04-2020 04:08 PM - edited 04-04-2020 04:55 PM
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.
04-04-2020 04:22 PM
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.
04-04-2020 04:31 PM
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.
04-04-2020 05:32 PM
Solution: The loop ran the correct number to times when I converted the for loop to a while loop.
04-04-2020 05:48 PM
04-04-2020 08:41 PM
@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.
04-06-2020 03:39 AM
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 ...
04-06-2020 07:36 AM
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...