Perl goto
Perl goto语句
Perl goto 语句是跳转语句。用于通过跳转到循环内的其他标签来转移控制。
共有三种goto形式:
goto LABEL:
它跳转到标有 LABEL 的语句并从那里恢复正常执行。
goto EXPR:
它是 goto LABEL 的概括。该表达式返回一个标签名称,然后跳转到该标签语句。
转到 &NAME:
对于当前正在运行的子程序,它替换对指定子程序的调用。
Perl goto 语句的语法如下:
goto LABEL
or
goto EXPR
or
goto &NAME
Perl goto 语句示例
让我们看一个简单的例子,在 Perl 语言中使用 goto 语句。
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";
}
输出:
You are not eligible to vote!
Enter your age:
11
You are not eligible to vote!
Enter your age:
5
You are not eligible to vote!
Enter your age:
26
You are eligible to vote!