Web | This Site

Perl Home
PERL Functions
© 2011 TutorialsPoint.COM

| Home |  | References |  | About TP |  | Advertising

# PERL goto Function

## Syntax

goto LABEL goto EXPR goto &NAME

## Definition and Usage

- The first form causes the current execution point to jump to the point referred to as LABEL. A goto in this form cannot be used to jump into a loop or external function.you can only jump to a point within the same scope.
- The second form expects EXPR to evaluate to a recognizable LABEL. In general, you should be able to use a normal conditional statement or function to control the execution of a program, so its use is deprecated.
- The third form substitutes a call to the named subroutine for the currently running subroutine. The new subroutine inherits the argument stack and other features of the original subroutine; it becomes impossible for the new subroutine even to know that it was called by another name.

## Return Value

- Nothing

## Example

Try out following example:

    #!/usr/bin/perl

    $count = 0;

    START:
    $count = $count + 1;

    if( $count > 4 ){
            print "Exiting program\n";
    }else{
        print "Count = $count, Jumping to START:\n";
        goto START;
    }

    It produces following result

    Count = 1, Jumping to START:
    Count = 2, Jumping to START:
    Count = 3, Jumping to START:
    Count = 4, Jumping to START:
    Exiting program

Advertisement

Online Image Processing

Indian Baby Names