04-08-2014 04:55 PM
I have a while loop nested inside a for loop to do a calculation of a model.
Lets say I am on the for loop counter 4. Suppose I wanted to keep track of the number of iterations on one the while loop, and if it exceeded a certain number say 100, exit the while loop. I am doing this to avoid my model calculation being stuck at a spot due to optimization issues. I now want to restart the calculations of for loop counter 4.
Is there a way to do this in labview?
Solved! Go to Solution.
04-08-2014 05:24 PM - edited 04-08-2014 05:25 PM
Do your own counter using a shift register.
If you want more detailed help, please attach your code.
04-08-2014 05:26 PM
Well first of all, if you are going to restart the loop with the same program inside it after it got stuck is it not just going to get stuck again creating a permanent loop in the code? Would you not just want to move on and have some sort of identifier that one of the for-loops got stuck?
But I would recommend simply nesting your while-loop inside of another while loop, then connect the exit for the out while-loop to some variable from the inner while-loop, so if the optimization did not occur properly then it simply repeats the inner while-loop.
Although I stick by my thoughts that you will just end up in a permanent loop if the optimization fails the first time.
04-09-2014 08:04 AM
Thanks. I nested my while loop inside a while loop and that worked.
04-09-2014 08:05 AM
ogk.nz
My optimizer initializes randomly for each trial. So if I re-initialize the optimizer, the chances are that the optimizer started at a better spot and moved progressively towards a solution.
I used your idea of nesting the while loop inside another and this helped solve my problem!
Thank you so much!
04-09-2014 08:35 AM
Since the max number of iterations is fixed and known before the loop starts, I would use an inner FOR loop, avoiding the constant checking of the iteration terminal. Show the conditional terminal to stop early.
04-16-2014 04:37 PM
Altenbach,
Apologize for the delay. But thanks for the comment. I tried out the inner FOR loop method and works fine for me.