Perl 中的 last函数

首页 / Perl入门教程 / Perl 中的 last函数

描述

这不是功能。 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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

快速上手Kotlin开发 -〔张涛〕

Web协议详解与抓包实战 -〔陶辉〕

Python核心技术与实战 -〔景霄〕

图解 Google V8 -〔李兵〕

Redis核心技术与实战 -〔蒋德钧〕

Linux内核技术实战课 -〔邵亚方〕

人人都用得上的写作课 -〔涵柏〕

代码之丑 -〔郑晔〕

AI 应用实战课 -〔黄佳〕

好记忆不如烂笔头。留下您的足迹吧 :)