当前位置:首页 » Perl » Perl last关键字

Perl last关键字

perl last 关键字学习例子,last实例代码,在线教程等

语法

last LABEL

last


定义和用法

不是一个函数。last关键字立即使循环当前迭代,成为最后一个循环控制语句。没有进一步的语句被执行,并结束循环。如果指定LABEL,然后它丢弃循环的识别LABEL,而不是目前的封闭循环。

返回值

    Nothing

例子

试试下面的例子:

#!/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";  It will produce foillowing result:

#by www.gitbook.net
Count is 1
Count is 2
Count is 3
Count is 4
Going to exist out of the loop
Out of the loop