while(true) is not fun
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:
var done = false;
while(!done) {
// do work
}But every C# dev should know how to write
while(true) { }
Real programmers use butterflies
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
They have their place. OS's use them quite a bit. Otherwise your process would never get any time slot.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:
var done = false;
while(!done) {
// do work
}But every C# dev should know how to write
while(true) { }
Real programmers use butterflies
:-D
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
-
They have their place. OS's use them quite a bit. Otherwise your process would never get any time slot.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
Yes, very common in daemons.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:
var done = false;
while(!done) {
// do work
}But every C# dev should know how to write
while(true) { }
Real programmers use butterflies
Or
var cowsHaveComeHome = false;
But I just write
while(true)...
whose meaning is crystal clear.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing. -
They have their place. OS's use them quite a bit. Otherwise your process would never get any time slot.
#SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun
Definitely. I have no inherent problem with them. They have their place. :)
Real programmers use butterflies
-
Or
var cowsHaveComeHome = false;
But I just write
while(true)...
whose meaning is crystal clear.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.if I truly need
while(true);
I'll use that. It's rare that I do though. Most of the time, I can get by with adone
variable and setting it inside the loop instead of usingbreak;
.Real programmers use butterflies
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
When I need an infinite loop I do this
var False = true;
while(False)
{
// code
} -
Or
var cowsHaveComeHome = false;
But I just write
while(true)...
whose meaning is crystal clear.
Robust Services Core | Software Techniques for Lemmings | Articles
The fox knows many things, but the hedgehog knows one big thing.I once had a code-reviewer change my code because I used a
while(true)
. This was done on the principle that one should never use awhile(true)
. The problem is, anyone looking at the code in future may see the condition he used and wonder why, as the condition can never be met. At least my original code is in the version history.“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
youAreWrong:
if (youThinkGotoIsEvil) goto youAreWrong;;P But seriously,
goto
is not intrinsically evil. But if it is the only thing you use in your codebase, you are evil! -
if I truly need
while(true);
I'll use that. It's rare that I do though. Most of the time, I can get by with adone
variable and setting it inside the loop instead of usingbreak;
.Real programmers use butterflies
honey the codewitch wrote:
Most of the time, I can get by with a
done
variable and setting it inside the loop instead of usingbreak;
.You are not the only one in that. I like this variation more too.
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
When I need an infinite loop I do this
var False = true;
while(False)
{
// code
}That's evil ... I like it :laugh:
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
BillWoodruff wrote:
are an abomination ... as evil as using goto
Try to write Assembly or program a PLC in STL without using JMP or similars...
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
-
BillWoodruff wrote:
are an abomination ... as evil as using goto
Try to write Assembly or program a PLC in STL without using JMP or similars...
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
suggested reading: [^] :)
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
for (;;)
{
Console.WriteLine("this, and while(true) loops, are an abomination ... as evil as using goto");// break; // oh, go on forever
}
but, writing this was fun :wtf: suggested reading: [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
well, my peers, and mentors, i intended this post as a tongue-in-cheek jiggery-pokery i hoped would not be taken seriously ... back in the days some of us fossils can remember, languages, like Fortran, had simple control structures; you had to use 'goto to exit a DO loop; that, and BASIC, are the context in which Dijkstra's famous hyperbolic essay took aim [^]. in today's high-level languages, like C#, the underlying use of jumps/gotos is abstracted away for very good reasons. if i see a while(true) in C#, i call that sloppy code that lacks documentation, and, is less maintainable, because you've got to study the interior code to figure out what, if anything, makes it stop. and, it never returns? [^]
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
suggested reading: [^] :)
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
state machines are a good argument for gotos. It is impossible as far as I know, to implement every scenario possible for a deterministic finite automata based state machine without using either array based tables, or goto statements. while/for/etc don't cut it because the flow can become too complicated for those constructs. There was a Knuth paper you linked to earlier** that presented a defense of goto that is similar to my defense of it just above. ** here's the code from that paper (Example 1):
for i := 1 step 1 until m do.
if A[i] = x then go to found fi;
not found: i := re+l; m := i;
A[i] := x; B[i] := 0;
found: B[i] := B[i]+I;rewritten without goto it's even worse (Example 1a):
i:=1;
while i < m and A[i] # x do i :-- i+1;
if i > m then ra := i; A[i] := x; B[i] ::= 0 fi;
B[i] := B[i]+I;Real programmers use butterflies
-
state machines are a good argument for gotos. It is impossible as far as I know, to implement every scenario possible for a deterministic finite automata based state machine without using either array based tables, or goto statements. while/for/etc don't cut it because the flow can become too complicated for those constructs. There was a Knuth paper you linked to earlier** that presented a defense of goto that is similar to my defense of it just above. ** here's the code from that paper (Example 1):
for i := 1 step 1 until m do.
if A[i] = x then go to found fi;
not found: i := re+l; m := i;
A[i] := x; B[i] := 0;
found: B[i] := B[i]+I;rewritten without goto it's even worse (Example 1a):
i:=1;
while i < m and A[i] # x do i :-- i+1;
if i > m then ra := i; A[i] := x; B[i] ::= 0 fi;
B[i] := B[i]+I;Real programmers use butterflies
i think you just hoisted my attempt to play Hamlet on his own petard :omg:
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
-
i think you just hoisted my attempt to play Hamlet on his own petard :omg:
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
I'm all kinds of no fun today, sorry. :~
Real programmers use butterflies
-
Microsoft's CodeDOM renderer for C# spits out loops like that. I've also seen Microsoft code that does it this way in the reference source for the .NET BCL. As far as the while, I prefer:
var done = false;
while(!done) {
// do work
}But every C# dev should know how to write
while(true) { }
Real programmers use butterflies
Just a preference. But yes, guilty.
var HellHasFrozen
..
while (!HellHasFrozen)If you see it, good chance I wrote that code. Also (!MurlocsAttacking), used in handlers for multiple unknown exceptions. I WarCraft too much.
Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.