Updated: 04/26/2017 by Computer Hope

Goto may refer to any of the following:

1. A programming statement that forwards a user to a different section of the program. Below is a basic example of how a goto may be used in Perl.

Goto example

use strict;
print "Please type your password: ";
my $password = <STDIN>;
if ($password =~ /secret/i) { 
     print "Success";
else { 
     goto start;

In the above example, when the program is run, it would continue to prompt the user for a password until he or she enters secret as the password. To repeat the prompt a "start:" label is placed at the start of the script and if "secret" is not entered the script uses the goto statement to go to the start label and repeat the prompt.

Tip: Although a goto statement is an easy method of moving around a program, it is considered bad practice to use excessively because it creates spaghetti code. However, in some cases, a goto may be the only option or the best solution. We feel that it is best left to the programmer to decide when and when not to use the goto statement and stay away from the endless debate of using or not using goto statements in your code.

2. Goto is also an MS-DOS and Windows command line command. See our goto command page for further information.

Control flow, JSR, Loop, Programming terms