Perl goto Statement

The Perl goto statement is the jump statement. 
It is used to transfer control by jumping to other label inside a loop.

There are three goto forms:

goto LABEL:
It jumps to the statement labeled with LABEL and resumes normal execution from there.

goto EXPR:
It is a generalization of goto LABEL. The expression returns a label name and then jumps to that labeled statement.

goto &NAME:

For currently running subroutine it substitutes a call to the named subroutine.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
LOOP:do  
print "You are not eligible to vote!\n";  
print "Enter your age\n";  
$age = <>;  
    if( $age < 18){   
       goto LOOP;  
    }  
    else{   
    print "You are eligible to vote\n";   
}  
Output:
You are not eligible to vote!
Enter your age:
16
You are not eligible to vote!
Enter your age:
12
You are not eligible to vote!
Enter your age:
22
You are eligible to vote!



<-- Previous || Next -->

1 comment: