Perl循环操作

1、while循环
while ( <expression> ) {
<statement_block>
}

2、until循环
until ( <expression> ) {
<statement_block>
}

3、for循环 ,如
for ($count=1; $count <= 5; $count++) {
# statements inside the loop go here
}

4、foreach循环 ,如
foreach $word (@words) {
if ($word eq "the") {
print ("found the word 'the'\n");
}
}

5、do..while循环
do {
statement_block
} while (condexpr);
do循环至少执行一次循环。

6、do..until循环
do {
statement_block
} until (condexpr);
do循环至少执行一次循环。

7、循环控制
退出循环为last,与C中的break作用相同;执行下一个循环为next,与C中的continue作用相同;PERL特有的一个命令是redo,其含义是重复此次循环,即循环变量不变,回到循环起始点,但要注意,redo命令在do循环中不起作用。

技术改变未来
原文地址:https://www.cnblogs.com/CodeTracker/p/4726729.html