Perl last 函数
描述
这不是函数。 last 关键字是一个循环控制语句,它立即使循环的当前迭代成为最后一次。 不再执行其他语句,循环结束。 如果指定了 LABEL,那么它将退出由 LABEL 标识的循环而不是当前封闭的循环。
语法
以下是此函数的简单语法 −
last LABEL last
返回值
这不会返回任何值。
示例
以下是显示其基本用法的示例代码 −
#!/usr/bin/perl
$count = 0;
while( 1 ) {
$count = $count + 1;
if( $count > 4 ) {
print "Going to exist out of the loop\n";
last;
} else {
print "Count is $count\n";
}
}
print "Out of the loop\n";
执行上述代码时,会产生以下结果 −
Count is 1 Count is 2 Count is 3 Count is 4 Going to exist out of the loop Out of the loop

