goto loops
-
Yes - I scored the post in a way I saw fit and gave reasons in the response I posted. Which I believe is actually the polite way of doing things!
Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.
Wow - looks like someone didn't agree with you, and didn't say why.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Wow - looks like someone didn't agree with you, and didn't say why.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001It's not something I'm going to lose any sleep over!
Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.
-
This article/blog[^] Shows situations where goto statements can be used to greater effect than other soloutions although I must confess I can see better ways to code some of the examples, that the author ignores. I was always taught to avoid goto's at all costs and have always stuck to this advice, however, like you, I have noticed collegues use them a lot.
Funny how no-one even the comments could come up with a really good alternative (I agree for simplicity, the && is approach is best). How would I do it?
bool Do(params Func<bool>[] args)
{
foreach (var a in args)
if (!a())
return false;
return true;
}
...if (Do(Step1, Step2, Step3, Step4, Step5, Step6, Step7))
Console.WriteLine("Brillant!");xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
Lucian-aSterX wrote:
i give up.
Why? You're not French...
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Funny how no-one even the comments could come up with a really good alternative (I agree for simplicity, the && is approach is best). How would I do it?
bool Do(params Func<bool>[] args)
{
foreach (var a in args)
if (!a())
return false;
return true;
}
...if (Do(Step1, Step2, Step3, Step4, Step5, Step6, Step7))
Console.WriteLine("Brillant!");xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
It's not something I'm going to lose any sleep over!
Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.
-
Wow - looks like someone didn't agree with you, and didn't say why.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001:laugh:
Pete
-
No serious programmer uses a
goto
. EDIT (After the 1 vote)---------------- Okay - maybe we all do - when wegoto
the bathroom....45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001modified on Monday, July 5, 2010 10:22 AM
-
Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!
Now your just setting him up to post code in the lounge and getting him flamed for doing so. I'm on to you ;P
-
No serious programmer uses a
goto
. EDIT (After the 1 vote)---------------- Okay - maybe we all do - when wegoto
the bathroom....45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001modified on Monday, July 5, 2010 10:22 AM
John Simmons / outlaw programmer wrote:
No serious programmer uses a goto.
The whimsical ones do though :-D
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...
You earn your upvote rights by scaring people. ;)
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!
10 Print "This Code is useless."
20 Goto 10"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...
Well if you must know I up voted him for the remark about the 1 vote and the goto the bathroom part. Could be that my sense of humor is a bit off today but I thought it was funny so...
-
10 Print "This Code is useless."
20 Goto 10"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...
-
Strange - when I post a comment along those lines, I get downvoted, but when you do it gets upvoted. Makes me think that some people here go more for the person than the message! Isn't the first time I have noticed that, though...
I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid
goto
everyone uses. Of course, the 1-voters can alsogoto
hell for all I care..45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid
goto
everyone uses. Of course, the 1-voters can alsogoto
hell for all I care..45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
I got 1-voted, and probably from the same person that 1-voted you. I edited it because I thought that's why I was 1-voted - I had neglected to mention the one valid
goto
everyone uses. Of course, the 1-voters can alsogoto
hell for all I care..45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Wasn't me even though I don't agree with you. But since you are so dead set I'm wrong, I challenge you: Show me ONE piece of code where a GoTo has a meaningful use!
I think the nested 'for' loop example is meaningful enough:
for (int i = 0; i < I_BOUND; i++) { for (int j = 0; j < J_BOUND; j++) { if (MyTestingFunction(i, j, k)) { goto LoopExit; } } } LoopExit:
Steve McConnell gives a few other examples here[^]. To be clear, I'm not saying there aren't other ways of doing this (as there clearly are), and I don't believe there are any situations where using a goto provides funtionality above and beyond other native constructs (though am willing to be proved wrong!). I just don't agree that you can categorically state that use of goto is *always* wrong.Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.
-
I think the nested 'for' loop example is meaningful enough:
for (int i = 0; i < I_BOUND; i++) { for (int j = 0; j < J_BOUND; j++) { if (MyTestingFunction(i, j, k)) { goto LoopExit; } } } LoopExit:
Steve McConnell gives a few other examples here[^]. To be clear, I'm not saying there aren't other ways of doing this (as there clearly are), and I don't believe there are any situations where using a goto provides funtionality above and beyond other native constructs (though am willing to be proved wrong!). I just don't agree that you can categorically state that use of goto is *always* wrong.Sarchasm : The gulf between the author of sarcastic wit and the person who doesn't get it.
It's probably easier, but I still don't think it's a good use in this case. Sort of like exiting a room through the window. I'm not an expert on this, but can you be sure that jumping out of a nested loop like that doesn't leave something not cleaned up properly, stack e.g.?