while (true) and for (; ; ) [modified]
-
Nishant Sivakumar wrote:
what it's meant to do.
Hang the app with an endless loop? :)
Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011
Christopher Duncan wrote:
Hang the app with an endless loop?
Only on a single core machine :-D
Regards, Nish
New article available: Resetting a View Model in WPF MVVM applications without code-behind in the view My technology blog: voidnish.wordpress.com
-
Christopher Duncan wrote:
Hang the app with an endless loop?
Only on a single core machine :-D
Regards, Nish
New article available: Resetting a View Model in WPF MVVM applications without code-behind in the view My technology blog: voidnish.wordpress.com
:laugh:
Christopher Duncan Author of The Career Programmer Watch Bad Programmer! - Premieres May, 2011
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
I use the while(true) consistently...in embedded apps. (AVR)
If you are cross-eyed and have dyslexia, can you read all right? http://www.hq4thmarinescomm.com[^] JaxCoder.com[^]WinHeist - Windows Electronic Inventory SysTem
-
I don't find many situations where I must use either. Something like while(!done) gives you a control over whether and when to exit, normal or abnormal.
Best, Jun
Not always. In
C
applications, for instance, you may know in the middle of the loop that you've to exit and while you may skip the following statements with anif
and then use the condition, I prefer an immediatebreak
.If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have only used them, or their equivalent in other languages, for testing something. Never in production.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
-
I just used while(condition); in a unit test to test an async method for retrieving a business object. I can't imagine a use for them in production code though.
There is no failure only feedback
That's not even in the same category.
Curvature of the Mind now with 3D
-
I just used while(condition); in a unit test to test an async method for retrieving a business object. I can't imagine a use for them in production code though.
There is no failure only feedback
any way, if you are targeting 4.0, check this: SpinUntil[^]
Curvature of the Mind now with 3D
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
-
I think I've used while true a few times, mostly in either complicated parser code, or early on when I was learning threading. It can make sense when side effects and the loop exit criteria are so intertwined that you can't separate them easily to reduce the exit to a single boolean. However, that's a huge flag to refactor/write your code so things aren't so intertwined. If you don't have the time/flexibility to do that, then I'd choose while (true) over creating a convoluted mess of a loop body just to have a boolean value to exit on.
Curvature of the Mind now with 3D
By the time your code gets too noxious to write a good exit condition, it's also too noxious to easily debug without dismantling the mess first. Unless you can write bugfree codethulus on the first attempt, there's no excuse for letting it get that bad in the first place.
3x12=36 2x12=24 1x12=12 0x12=18
-
any way, if you are targeting 4.0, check this: SpinUntil[^]
Curvature of the Mind now with 3D
-
By the time your code gets too noxious to write a good exit condition, it's also too noxious to easily debug without dismantling the mess first. Unless you can write bugfree codethulus on the first attempt, there's no excuse for letting it get that bad in the first place.
3x12=36 2x12=24 1x12=12 0x12=18
Yeah, I guess I'm too used to batting cleanup and having to pick my battles.
Curvature of the Mind now with 3D
-
I don't understand your other reply but this one is gold! Thanks for that I'm going to use it immediately.
There is no failure only feedback
All I'm saying is that while(true) { do something repeatedly } sometimes has a place in real code. The other while(checkSharedVariable) {}; is just a good way to kick up your CPU power consumption.
Curvature of the Mind now with 3D
-
All I'm saying is that while(true) { do something repeatedly } sometimes has a place in real code. The other while(checkSharedVariable) {}; is just a good way to kick up your CPU power consumption.
Curvature of the Mind now with 3D
-
:-D
Curvature of the Mind now with 3D
-
Ah, I'm going to modify my original post. I wasn't referring to the preference between the 2, but the use of infinite loops, especially if there is no breaks to exit the loop. I guess we have a crash-only design for some applications.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
Those constructs are usually seen in non-ineractive microprocessor embedded systems - I use them all of the time for the main "idle loop". I rely on a watchdog timer to restart the application if something hangs.
Steve _________________ I C(++) therefore I am
-
Yeah, I guess I'm too used to batting cleanup and having to pick my battles.
Curvature of the Mind now with 3D
-
What are your views on these? How often do you use or see them and in what cases? Just curious, it's a little debate with my project's Architect. To clarify, I don't mean the preference between the 2, but the use of such loops in production.
"Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" — Hunter S. Thompson
modified on Thursday, March 10, 2011 12:10 PM
The only place I can remember using endless loops is in thread procedures. There often is no break, but of course I catch the ThreadAbortException to exit the loop. For example, a 3D rendering thread would be started at the beginning of the application and render as many frames as fast as it can until the thread is ended. Ending threads with an exception always appeared a little strange to me, because this definitely is changing the program flow with exceptions, but at least it has worked as expected up to now.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011