When is the usage of GOTO acceptable?

  • (2 Pages)
  • +
  • 1
  • 2

27 Replies - 17744 Views - Last Post: 13 July 2012 - 04:00 PM

#16 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 12:45 PM

I going to go with the following.
Spoiler

Was This Post Helpful? 0
  • +
  • -

#17 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 04:12 PM

Original Code came from this thread

Slight tweak, to use the conditional exceptions and a separate ConfirmReply Function.
Spoiler

Was This Post Helpful? 1
  • +
  • -

#18 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 463
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 04:52 PM

can i ask a question why are you throwing the exception in the second catch instead of showing the error message there and just let it exit on its own?
Was This Post Helpful? 0
  • +
  • -

#19 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 05:18 PM

Huh? Which are you refer as the second there are 5 catches
Was This Post Helpful? 0
  • +
  • -

#20 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1029
  • View blog
  • Posts: 4,007
  • Joined: 02-July 08

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 08:31 PM

MS uses them within the framework. I myself found place where I needed it once.
Was This Post Helpful? 0
  • +
  • -

#21 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,457
  • Joined: 08-June 10

Re: When is the usage of GOTO acceptable?

Posted 06 September 2011 - 08:41 PM

Needed is a strong word. I'm still interested in finding a situation where they are truly necessary, not just expedient.
Was This Post Helpful? 0
  • +
  • -

#22 UziTech  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 64
  • Joined: 26-October 10

Re: When is the usage of GOTO acceptable?

Posted 07 September 2011 - 02:12 PM

View PostCurtis Rutland, on 06 September 2011 - 09:41 PM, said:

Needed is a strong word. I'm still interested in finding a situation where they are truly necessary, not just expedient.


GOTO is never NEEDED in modern languages.

One thing I always use gotos for is if I need to go to the same place from multiple different locations. The same could be done with while loops and flags but that means more code and more ram wasted on flag variables.

In my opinion GOTO's are meant for code readability, in some situations they can make the code easier to read but if there are too many of them they can make it harder to read.
Was This Post Helpful? 0
  • +
  • -

#23 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 243
  • Joined: 29-November 08

Re: When is the usage of GOTO acceptable?

Posted 08 April 2012 - 05:10 PM

I'm not sure if you actually needed goto in this case but there was A vb.net Challenge to try and produce the Numbers 1 to 10 using at least 10 Different Loops
sadly this was the first loop I thought of
Sub GoToLoop()
    Dim number As Integer = 1
myLoop:
    Console.WriteLine(number)
    If number >= 10 Then Exit Sub
    GoTo myLoop
End Sub



I should be shamed but I do admit it IS a way to create a loop
Was This Post Helpful? 0
  • +
  • -

#24 pradeep1210  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 56
  • Joined: 08-May 12

Re: When is the usage of GOTO acceptable?

Posted 10 May 2012 - 05:35 AM

View PostBraber01, on 09 April 2012 - 05:40 AM, said:

I'm not sure if you actually needed goto in this case but there was A vb.net Challenge to try and produce the Numbers 1 to 10 using at least 10 Different Loops
sadly this was the first loop I thought of
Sub GoToLoop()
    Dim number As Integer = 1
myLoop:
    Console.WriteLine(number)
    If number >= 10 Then Exit Sub
    GoTo myLoop
End Sub



I should be shamed but I do admit it IS a way to create a loop

And it would result in an endless loop eventually crashing your program.
This is also one of the reasons why the use of GOTO keyword is discouraged. You need to be very careful when using this GOTO keyword.

While I was using this keyword too very often in VB6 programs, I couldn't find any legitimate situation where I couldn't manage without this keyword ever since I switched over to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#25 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: When is the usage of GOTO acceptable?

Posted 10 May 2012 - 05:38 AM

Goto is used a lot in the under the hood code, produced by the compiler for the Async and Wait / Iterator coming in the next version of vb.net
Was This Post Helpful? 0
  • +
  • -

#26 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,457
  • Joined: 08-June 10

Re: When is the usage of GOTO acceptable?

Posted 10 May 2012 - 07:33 AM

That's fine. I trust the compiler's output more than I do the people writing the code.
Was This Post Helpful? 0
  • +
  • -

#27 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,979
  • Joined: 19-May 09

Re: When is the usage of GOTO acceptable?

Posted 06 June 2012 - 07:52 PM

GOTOs are entirely necessary when you want to increase maintenance overhead, if you are the consultant who is doing the maintenance. Great way to make money, because nobody else can figure out your code.
Was This Post Helpful? 0
  • +
  • -

#28 ghostinak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-July 12

Re: When is the usage of GOTO acceptable?

Posted 13 July 2012 - 04:00 PM

The only acceptable use of GOTO (IMO) is as a reminder that the present is better than the past.

The one exception is when porting the original Star Trek game.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2