|
Or
var cowsHaveComeHome = false; But I just write
while(true)... whose meaning is crystal clear.
|
|
|
|
|
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 a done variable and setting it inside the loop instead of using break; .
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 using break; . 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.
|
|
|
|
|
Message Closed
modified 28-Sep-20 9:01am.
|
|
|
|
|
GuyThiebaut wrote: I once had a code-reviewer change my code because I used a while(true) . So did I - because it was supposed to be 'while(1)'.
Reason: Code should be compilable with K&R C, which didn't provide bool values/constants.
|
|
|
|
|
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
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
probably my silliest function name currently in use is _HasExtraNonsense() because the alternative (spelling out what "nonsense" means) would yield a function name as wide as the screen
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: But every C# dev should know how to write while(true) { }
while (true)
{
Console.WriteLine("C# is better than Javascript!");
}
Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason?
Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful?
--Zachris Topelius
Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies.
-- Sarah Hoyt
|
|
|
|
|
At least GOTO got a name of a style - spaghetti code!
|
|
|
|
|
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.
|
|
|
|
|
Definitely. I have no inherent problem with them. They have their place.
Real programmers use butterflies
|
|
|
|
|
When I need an infinite loop I do this
var False = true;
while(False)
{
}
|
|
|
|
|
That's evil ... I like it
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.
|
|
|
|
|
youAreWrong:
if (youThinkGotoIsEvil) goto youAreWrong;
But seriously, goto is not intrinsically evil. But if it is the only thing you use in your codebase, you are evil!
|
|
|
|
|
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
|
|
|
|
|
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
«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
|
|
|
|
|
Knuth's "Example 1" problem using structured statements for alternate loop exits:
for i in 1:m do
// main loop body; may contain any number of statements:
while A[i] != x; // premature loop termination if x is found
exitwhile // do this on premature loop termination, i.e. "found"
B[i]++;
exitfor // do this if loop reaches end of (valid) A[], i.e. "not found"
A[i] := x;
B[i] := 1;
m = i; // new search limit for subsequent x searches
endfor I really miss this construct; I found it truly useful, but have seen it in a single language only, 30+ years ago.
Note that both the exitwhile and exitfor clauses are within the scope of the loop statement, with access to the loop control variable and any other variable declared within the loop. (This is essential to the usability of the construct.)
|
|
|
|
|
Yeah - i posted an alternate he provided in that same comment.
Real programmers use butterflies
|
|
|
|
|
I didn't find the alternative nearly as explicit and comprehensible as the exitfor/exitwhile mechanism.
|
|
|
|
|
True, it's not. I was simply pointing out that he *did* produce an alternative. As for me I'd prefer a state machine example.
Compiled state machines requires gotos (i'm excluding array driven ones here). It's true that some state machines can be implemented without them, but not all of them can.
The reason is you need to goto into and out of loops all of the time, just because of how they work. Furthermore state machines more clearly translate to drawn graphs which then directly map to the code, making the code easy to follow if it uses gotos, but not if it uses the array driven style. In this article[^] there's some coverage of what that looks like.
Real programmers use butterflies
|
|
|
|
|
Where does the block of the for statement end, please? I looked at the original article, page 266 for those interested, but I'm still not clear on it.
honey the codewitch wrote: 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;
|
|
|
|