Perl last 语句2024 年 8 月 29 日 | 阅读 2 分钟 Perl 中的 last 语句类似于 C 语言中的 break 语句。 它用于在循环内部立即退出循环。 换句话说,last 条件会迭代循环。 下面给出了 Perl 中 last 语句的语法 Perl last 语句示例以下是一个简单的示例,展示了 Perl last 语句。 输出 Please enter an item to know the price: boots boots costs is Rs. 1200 Please enter an item to know the price: top top is not in our list. We apologise!! 在上面的程序中
带标签的 Perl last 语句使用 Perl last 语句本身,您只能退出最内层的循环。 如果要退出嵌套循环,请在外部循环中放置一个标签,并将标签传递给 last 语句。 如果使用 last 语句指定了 LABEL,则执行将跳出遇到 LABEL 的循环,而不是当前封闭的循环。 下面给出了带有 LABEL 的 Perl last 语句的语法 带 LABEL 的 Perl last 语句示例输出 Please enter an item to know the price: jaggi boots costs is Rs. 800 Please enter an item to know the price: jeans jeans is not in our list. We apologise!! 上面的程序的工作方式相同,只是它要求用户再次输入搜索键,如果找不到匹配项的话。 使用了两个标签 OUTER 和 INNER。 在 foreach 循环内部,如果找到匹配项,我们将退出两个循环,因为 OUTER 标签被传递给 last 语句。 下一个主题Perl next 语句 |
我们请求您订阅我们的新闻通讯以获取最新更新。