这不是功能。 last关键字是一个循环控制语句,该语句立即导致循环的当前迭代变为最后一个。不再执行任何语句,循环结束。如果指定了LABEL,则它将退出LABEL标识的循环,而不是当前封闭的循环。
以下是此函数的简单语法-
链接:https://www.learnfk.comhttps://www.learnfk.com/perl/perl-last.html
来源:LearnFk无涯教程网
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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)