A Conversation for The GOTO Statement

In some languages, such as BASIC & Qbasic...

Post 1


GOTO is faster then calling a sub-routine. I dont see anything wrong with using GOTO, unless you over use it; but isn't that true for anything?

In some languages, such as BASIC & Qbasic...

Post 2

SchrEck Inc.

HI Sage, the keyword in this context is... modularization. You couldn't do independent subroutines, callable from everywhere, with GOTO because you couldn't automatically return to the place of calling. GOTO and GOSUB are completely different concepts and normally not interchangeable. And on modern computers with modern development tools, the performance of certain constructs or program instructions doesn't really matter in 99 percent of your code.

In some languages, such as BASIC & Qbasic...

Post 3


While the use of a GOTO statement can be useful at times; I've found using them to be like a marble tower toy that I had when I was a boy. You could insert a marble into it from different points and the gods only knew where it would come out. The precise point of exit actually was based on how you stacked the layers of the toy. However, more often than not, the marble either dropped out somewhere I didn't expect or worse... got stuck inside and I'd have to take the whole thing apart.
If you are going to use GOTO's in a program, I would suggest using interesting labels for your exit points. GOTO BORNEO, GOTO BOBSPLACE, or the classic GOTO (a Judeo-Christian place of eternal flaming punishment) add color to your program for those who come along later to maintain it, or to fix the mess you've made of your program through the overuse of GOTOs.

In some languages, such as BASIC & Qbasic...

Post 4


you seem to forget that almost all languages tend to end up with the goto statement in them somehow, due to its inherent usefullness.

if your language is extensible, you can easily cut down on the number of goto's you need (and if you don't believe me, try reading any large bbcbasic program)

if you can comment properly, most of those problems with ending up where you didn't expect to disappear as well.

In some languages, such as BASIC & Qbasic...

Post 5


GOTO is really pointless... After all, the reason msot BASIC programmers increment their lines by 10 is so they can go back later and instead of retyping EVERY line of code just add a line like 15 in between 10 and 20 without mesing up the structure of the program. And because the entire program is loaded into RAM before execution, you could have a program like this:
10 PRINT "Yeah, that's right"
20 GOTO 10
15 PRINT "Ooops, wrong number"
and it would still return
Yeah that's right
Oooops, wrong number
repeated over and over again. So if you're going to use GOTO, there are only two options, really: Substitute in GOSUB and RETURN for a subroutine (so it can be called by other places in the code) or just type the code in where you would normally put the GOTO! Amateur programmers use the GOTO to fix bugs by making some sort of program like this:

10 REM Top of prgm
20 REM Body of prgm
30 REM There was an error here
40 GOTO 80
50 REM Rest of program
60 REM Prgm ends here
70 END
80 REM Bug fix here
90 GOTO 50

And now I'm ranting so I'll stop. Conclusion: GOTO is unnecessary. Use GOSUB/RETURN instead.

Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more