Perl goto 语句

2024年8月29日 | 1 分钟阅读

Perl goto 语句是跳转语句。 它用于通过跳转到循环内的其他标签来转移控制权。

有三种 goto 形式

goto LABEL

它跳转到标有 LABEL 的语句,并从那里恢复正常执行。

goto EXPR

它是 goto LABEL 的一个概括。 该表达式返回一个标签名称,然后跳转到该标签语句。

goto &NAME

对于当前正在运行的子例程,它将调用替换为指定子例程的调用。

Perl goto 语句的语法如下


Perl goto 语句示例

让我们看一个简单的示例,在 Perl 语言中使用 goto 语句。

输出

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!
下一个主题Perl 注释