View the Most Wanted LQ Wiki articles.
LinuxQuestions.org > Linux Wiki > Goto

From LQWiki

Jump to: navigation, search

goto statements are used in primitive programming languages (and often implemented in more mature languages that should know better) to provide a method of moving to an arbitrary point in the program's code.

The canonical example is the first BASIC program that anyone ever writes:

10      PRINT "Hello, World!"
20      GOTO 10

goto statements are generally disparaged because, in most situations, similar results can be engineered without the use of a goto. For example, the same result can be reached using a loop:

10 LOOP
20   PRINT "Hello, World!"
30 UNTIL FALSE

advantage of this notation is that you can more intuitively predict (and change!) when the loop will stop.


Personal tools