07-20-2006 08:42 AM
07-20-2006 09:27 AM
Remember that the underlining code for a for loop and a while loop is the same its just a section of code which uses a conditional jump to the lableed start and repeats until the condition is false/true (jump on zero, jump on not zero). The C language specifications is one of the most flexable semantics and allows many implimentations of the same compiled code. The only reason for an infinite while loop I have found is in embedded programming (microcontrollers) where the application runs indefinitly. In labview I only use an infinite loop for debugging purposes and early implementations where a force quit is not dangerous. A conditional stop is almost always a better solution, so an elegant and safe shutdown procedure can be added (ie close all resources, shutdown atached equiptment to safe states ...). As for the i counter in an infinite loop it can be very nice to have for performing periodic actions such as i=0 for an initialization code or i%n = zero to do error checking or time consuming operations such as file i/o or GUI updates. Hope this helps. ***One thing I do think is that the i indicator should be optional in the while loop. It seems confusing and (all be it very slightly) inefficient to have an index when one is not used (it adds i++ code to each itteration, although this can be optimized out by a compiler I dont know if it actually is).
Paul
07-20-2006 09:40 AM
Hi
Although I know the construct, I never had to use it up to now and I also don't know where it is helpful. In my oppinion you will have to terminate each loop once.
Compared to text languages (like C or Java) there is not a break keyword (or better keyvi) available, so there is no way to stop an infinite loop.
For me (and that's really just my oppinion) an infinite loop is not good programming. Ok - I don't know how it is on HW-systems (FPGAs or microprocessors) with no user interface, as I just work on PCs, but on that target I see no use of an infinite loop.
07-20-2006 09:49 AM
07-20-2006 10:12 AM
07-20-2006 10:24 AM
07-20-2006 10:29 AM
As was said earlier, it seems strange to talk about infinite looping when you are concerned about the loop termination conditions.
@Michael Winkler wrote:
Well, I think as a C developer it is usual to create an infinite loop with a loop with the condition on the beginning ( while(1) or for( ; ; ) ), not on the end ( do-while(1) ). To be strict, it is a difference if the loop condition stands at the beginning or on the end because the first has minimum passes 0 and the second 1.
To create a "real" while loop wire the output of your terminating condition to a case structure surrounding the rest of the code within the loop.
07-20-2006 10:49 AM
Michael,
I don't see much need for an infinite for loop either but please go to http://digital.ni.com/applications/psc.nsf/default?OpenForm&temp1=&node= and make your suggestion. You never know what will happen.
Also, check out the discussion on a new for loop with break at http://forums.ni.com/ni/board?board.id=features.
07-20-2006 10:57 AM
A point on my suggestion about making the i terminal optional; is this a good idea? There are many times that I do not use an index in my loop code, it would be nice to turn it off when not used (ie a right click on the loop and have a no indexing option) This can speed up simple processing loops such as the loop while(not done){value = value+new_value;}, an i++ would double the computational time. Does any one know if this code is optimized out if the i terminal is not wired? If this optimization is not used it should be done by labview for the while loops. Removing the index is not possible ort the for loop since the index is the criteria for a termination. I have also struggled with the do break option in the loop there have been a few instances where I had to fake it with a case structure inside of the loop (ie on berak dont execute the code, still not as efficient as a break but not too bad). Other than broken data flow why was the break structure omitted from the G specifications? I think these questions dont deserve 1 star, since it gets us all thinking about labview at an syntatical level, and helps understand the strengths and weaknesses of labview as a programming language.
Paul
07-11-2018 10:03 PM
Infinite loops are very much part and parcel of embedded programming.