Jump to content

Why doesn't anyone use Goto anymore?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
21 replies to this topic

#1
Donovan

Donovan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 798 posts
Why doesn't anyone use a goto statement anymore?

where ever you put goto name; it will go to any section with

name:

So for example.

BLOCK OF CODE HERE
goto name;

BLOCK OF CODE

BLOCK OF CODE

name:
(It would then start at the next block of code after name.)
BLOCK OF CODE


This will work up or down. For example.

mainMenu:
BLOCK OF CODE

BLOCK OF CODE

BLOCK OF CODE

goto mainMenu;
Posted Image
+Friend Me | My Graphics | Forum Rules | Help Forum | Forum FAQ

#2
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
Because other programming structures largely make goto kludgey and irrelevant, relegating "proper" use of goto to very few situations. The ones you show are not them. ;)

#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Goto also can't be used to go into a try statement, making it's practical use in C++ very limited.

Goto is also difficult to read, since there's no way for you to know where that label is short of some kind of very detailed IDE.

I believe there may be uses for Goto... I've just never seen them.
Wow I changed my sig!

#4
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
An article I stumbled upon: Code Complete, First Edition

#5
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts
I used to use it a lot in basicA
and occasionally in QuickBasic,
since then I haven't used it.
(whoops... showing my age)

#6
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
QuickBasic... the good old days when you could start a loop at 0 and poke 0 into the loop variable :) Until DOS froze, that is.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#7
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
I think goto just makes it terribly hard to read and maintain code. Structured programming took over.

#8
debtboy

debtboy

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 916 posts

WingedPanther said:

QuickBasic... the good old days when you could start a loop at 0 and poke 0 into the loop variable :) Until DOS froze, that is.
Yea, back when you could output whatever binary pattern you
wanted on the bits of your printer port w/ only 1 command!!
The good old days... :D

#9
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
People don't use goto because of the very good reasons given by Edsger Dijkstra in his article: "Goto Statement Considered Harmful".
I think the only justifiable gotos in C are in lieu of exceptions. In any case, one should just use setjmp.h
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#10
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
One thing that I forget to keep in mind when developing is that I may not always be the person working on the code I'm writing. This sometimes results in code that is messy and hard to maintain due to bad naming, structure, or lack of clear comments.
-CDG10620
Software Developer

#11
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts

Aereshaa said:

I think the only justifiable gotos in C are in lieu of exceptions. In any case, one should just use setjmp.h
Ick.

/imo

#12
Termana

Termana

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,057 posts
Goto can make code hard to follow, or drag functions out when it could be split into two (or more) functions. It can also make modifying code hard. IMO.

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!