Goto
Jump to navigation
Jump to search
Goto statements are used primarily in primitive programming languages (though are often still available in higher-level languages) 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. In more complex applications, debugging or maintaining code with many goto statements can be enormously difficult.