目录

last

描述 (Description)

这不是一个功能。 最后一个关键字是一个循环控制语句,它立即导致循环的当前迭代成为最后一个。 不执行进一步的语句,循环结束。 如果指定了LABEL,那么它将退出LABEL标识的循环,而不是当前封闭的循环。

语法 (Syntax)

以下是此函数的简单语法 -

last LABEL
last

返回值 (Return Value)

这不会返回任何值。

例子 (Example)

以下是显示其基本用法的示例代码 -

#!/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
↑回到顶部↑
WIKI教程 @2018