Perl continue 语句

Perl 教程 · 2019-02-26 23:12:13

Perl continue 块通常在条件语句再次判断前执行。

continue 语句可用在 while 和 foreach 循环中。

语法

while 循环中 continue 语句语法格式如下所示:

while(condition){
   statement(s);
}continue{
   statement(s);
}

foreach 循环中 continue 语句语法格式如下所示:

foreach $a (@listA){
   statement(s);
}continue{
   statement(s);
}

实例

while 循环中使用 continue 语句:

实例

#/usr/bin/perl $a = 0; while($a < 3){ print "a = $a\n"; }continue{ $a = $a + 1; }

执行以上程序,输出结果为:

a = 0
a = 1
a = 2

foreach 循环中使用 continue 语句:

实例

#/usr/bin/perl @list = (1, 2, 3, 4, 5); foreach $a (@list){ print "a = $a\n"; }continue{ last if $a == 4; }

执行以上程序,输出结果为:

a = 1
a = 2
a = 3
a = 4

点击查看所有 Perl 教程 文章: https://codercto.com/courses/l/19.html

查看所有标签

Types and Programming Languages

Types and Programming Languages

Benjamin C. Pierce / The MIT Press / 2002-2-1 / USD 95.00

A type system is a syntactic method for automatically checking the absence of certain erroneous behaviors by classifying program phrases according to the kinds of values they compute. The study of typ......一起来看看 《Types and Programming Languages》 这本书的介绍吧!

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器