LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create for loop USING a while loop

Mine will run 10 times regardless only because I had that value wired in as a constant.  That could just as easily be a control.

 

Yours will run 10 times, or maybe 9, or maybe only once.  It would look like it would run 10 times because you have the constant in there, but the actual number of iterations will vary because of the additional code you put in there in ways that would not at all be predictable to the person trying to implement that loop.

 

I have to disagree with you.  The poster's original request is to have a loop that runs N number of times starting at any given value besides the value 0 that the i terminal naturally gives.  Mine does that.  Yours will run anywhere from N all the way down to only 1 time if the start value happens to be between 1 and N.  Very inconsistent, unintuitive behavior and not at all what the poster asked for.

0 Kudos
Message 11 of 16
(810 Views)

@Ravens Fan wrote:
 

 

I have to disagree with you.  The poster's original request is to have a loop that runs N number of times starting at any given value besides the value 0 that the i terminal naturally gives.  Mine does that.  Yours will run anywhere from N all the way down to only 1 time if the start value happens to be between 1 and N.  Very inconsistent, unintuitive behavior and not at all what the poster asked for.


Mine was designed to control the number of loop iterations, which is what I though the OP wanted.  It does this.  For instance, if 7 is entered it will loop 3x because 10 is the max.  True, it will loop an additional 10 times if the control is increased beyond 10, but that can easily be remedied, just like yours can with lack of controlSmiley Wink.  You could simply make the upper limit of the control 10. It does not have unpredicable behavior, except in the case with the aforementioned point made by you, which as I stated, is easily remedied.

 

If I am off the mark with the OPs requirement, my mistake.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
0 Kudos
Message 12 of 16
(804 Views)

Let me clarify what i'm trying to do for my inital post wasn't very clear...

So my labVIEW program will import a .csv file and turns it into an array where it gets fed into a loop with array indexing. By hooking up the iteration (i) to the index array function, it will read the .csv file line by line and pulling out elements.

The individual elements will get fed into a case selector (string) then it'll run the corresponding case. For example, (Temp, 25) will send the string 'temp' into the case selector then it'll switch to case 'temp' where 25 will get passed into it.

 

The PROBLEM i have now is when CALL_SUBROUTINE FUNC1 gets passed, I want to jump to SUBROUTINE FUNC1 (means (i) will need to change, through feedback?) then continue reading/passing info UNTIL it gets to END_SUBROUTINE FUNC1, at this point, I need (i) to jump back to after CALL_SUBROUNTINE FUNC1 and continue, which will be (temp, 50) next and so on.

 

At this point, for something like this to work, I need to be able to control the iteration variable, (i) of a loop, where I can feed back into it whenever i need to jump to a specific iteration count. Another way is to create my own loop with my own iteration variable and change the iteration count whenever i want through feedback most liekly

I hope this makes sense...

 

Thank you!

0 Kudos
Message 13 of 16
(786 Views)

What you are describing sounds much more like a state machine. A state machine is implemented using a while loop and a case structure. It will also have the necessary shift registers needed to pass the specific data you need to control which states need to be executed as well as counts to determine how many times something needs to be done. If I were you I forget about using a for loop and trying to force a round peg into a square hole and describe what you want to do in terms of a state machine. I think this will be easier to implement and easier to understand.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 14 of 16
(772 Views)

Thanks for the suggestions, but I figured out a solution and now my program runs the way I want, yay!

 

I made this little adder function inside of the while loop. I used the labview add function where one input is 1 (can be anything really, variable, etc) and the other input is the output of itself. This means as the while loop is going, it'll continually add 1 to itself and spit out the output +1. Basically, I'm using this to replace i and by wiring this into the index array function, I can choose whatever element I want from the .csv file.

0 Kudos
Message 15 of 16
(710 Views)

In other words, you implemented the solution given at the beginning. If you used a feedback node instead of the shift registers shown, you should know that the two are pretty much inter-changeable.

0 Kudos
Message 16 of 16
(692 Views)