Click here to Skip to main content
15,902,198 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: goto statement Pin
jschell18-Nov-13 8:13
jschell18-Nov-13 8:13 
GeneralRe: goto statement Pin
Stefan_Lang13-Nov-13 21:22
Stefan_Lang13-Nov-13 21:22 
GeneralRe: goto statement Pin
jschell18-Nov-13 8:17
jschell18-Nov-13 8:17 
GeneralRe: goto statement Pin
Stefan_Lang18-Nov-13 20:54
Stefan_Lang18-Nov-13 20:54 
GeneralRe: goto statement Pin
jschell19-Nov-13 10:39
jschell19-Nov-13 10:39 
GeneralRe: goto statement Pin
Stefan_Lang19-Nov-13 22:33
Stefan_Lang19-Nov-13 22:33 
GeneralRe: goto statement Pin
jschell20-Nov-13 9:54
jschell20-Nov-13 9:54 
GeneralRe: goto statement Pin
Bill_Hallahan11-Nov-13 17:39
Bill_Hallahan11-Nov-13 17:39 
Stephan_Lang wrote:

"The main reason however that you shouldn't use goto is that there is no benefit. Over the past 30 years I've used, learned about, read about, and had plenty of discussions about goto. In all that time I've never heard or read one compelling argument in favor of using it. Yes, you can use it to reduce or avoid nesting, or otherwise reduce the amount of code. But that by itself is not a valid argument in my book."


Over the past 39 years, I've never used a goto in C or C++. I did use the goto in Basic. My first computer only had GWBasic and assembly language.

Some situations where there is a benefit to a using goto are mentioned in Hopkin's 1979 paper, "A Case For The Goto", which I believe was written in response to Dijkstra's paper, "A Case Against The Goto". Even with modern compiler optimizations, the examples in both papers still apply today.

I would, and have, gone to extreme lengths to avoid using a goto, for the reasons you mentioned. Even when I've had to jump out of the center of multiple nested loops, I used an exit-flag and an if-statement with a break after each loop. Still, there is no question that this is a bit slower than using a goto to jump out of the center.

I have coded many real-time Digital Signal Processing algorithms with streaming data. Often these algorithms must be fast enough to keep up with the input data stream. In some cases, I have had to write special assembly code routines for some calculations, otherwise the algorithm couldn't keep up with the input data. Unfortunately, unlike the C language, assembly language isn't portable.

Using a goto is likely to only result in a very small speed increase. I doubt that using a goto is typically justified, if it is ever justified. Still, there can be a benefit to using one, and I acknowledge that there might be some fringe case where, after other necessary algorithm and implementation optimizations have been done, using a goto is warranted. Thus I reject any dogmatic statement to the contrary.

I say, as a general rule, use all possible techniques to avoid using a goto. I've always been able to avoid the goto. You can probably avoid the goto too.

Check out one of the links in my first message in this thread where issue of dogma and the 'goto' is addressed. I also showed a loop construct as a way to avoid using a goto in some situations in that message.

modified 11-Nov-13 23:56pm.

GeneralRe: goto statement Pin
vl212-Nov-13 0:47
vl212-Nov-13 0:47 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:35
Bill_Hallahan12-Nov-13 13:35 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 1:27
Stefan_Lang12-Nov-13 1:27 
GeneralRe: goto statement Pin
vl212-Nov-13 1:33
vl212-Nov-13 1:33 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:42
Bill_Hallahan12-Nov-13 13:42 
GeneralRe: goto statement Pin
Mardy Git10-Nov-13 23:32
Mardy Git10-Nov-13 23:32 
GeneralRe: goto statement Pin
werinus11-Nov-13 0:11
werinus11-Nov-13 0:11 
GeneralRe: goto statement Pin
vl211-Nov-13 7:42
vl211-Nov-13 7:42 
GeneralRe: goto statement Pin
werinus11-Nov-13 20:42
werinus11-Nov-13 20:42 
GeneralRe: goto statement Pin
vl212-Nov-13 0:41
vl212-Nov-13 0:41 
GeneralRe: goto statement Pin
Stefan_Lang12-Nov-13 1:36
Stefan_Lang12-Nov-13 1:36 
GeneralRe: goto statement Pin
vl212-Nov-13 1:43
vl212-Nov-13 1:43 
GeneralRe: goto statement Pin
Bill_Hallahan12-Nov-13 13:46
Bill_Hallahan12-Nov-13 13:46 
GeneralRe: goto statement Pin
Fran Porretto11-Nov-13 0:54
Fran Porretto11-Nov-13 0:54 
GeneralRe: goto statement Pin
Stefan_Lang11-Nov-13 1:48
Stefan_Lang11-Nov-13 1:48 
GeneralRe: goto statement Pin
Fran Porretto11-Nov-13 2:06
Fran Porretto11-Nov-13 2:06 
Generalgoto vs. exception Pin
Member 1039410411-Nov-13 4:15
Member 1039410411-Nov-13 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.