last: 立即中止循环,就像C语言中的break
next:
有时候并不要求立刻退出循环,但是需要立刻结束当前这次迭代,这就是next操作符的用处,
它会跳到内层循环块的底端。在next之后,程序将会继续执行循环的下次迭代
redo操作符:
redo,它能将控制返回到本次循环的顶端,不经过任何条件测试,也不会进入下一次循环迭代。
redo 则会重新执行这次的迭代,
next:而next会继续下一次迭代
[oracle@jhoa 7]$ cat 7.pl
for ($i = 1;$i <= 10;$i++){ #从1数到10
next if ($i == 5);
print "I can count to $i!
";
}
[oracle@jhoa 7]$ perl 7.pl
I can count to 1!
I can count to 2!
I can count to 3!
I can count to 4!
I can count to 6!
I can count to 7!
I can count to 8!
I can count to 9!
I can count to 10!
last:
[oracle@jhoa 7]$ cat 10.pl
for ($i = 1;$i <= 10;$i++){ #从1数到10
if ($i == 5){last;}
else{
print "I can count to $i!
";
}}
[oracle@jhoa 7]$ perl 10.pl
I can count to 1!
I can count to 2!
I can count to 3!
I can count to 4!
redo:
[oracle@jhoa 7]$ cat 10.pl
for ($i = 1;$i <= 10;$i++){ #从1数到10
if ($i == 5){redo;}
else{
print "I can count to $i!
";
}}
[oracle@jhoa 7]$ perl -w 10.pl
I can count to 1!
I can count to 2!
I can count to 3!
I can count to 4!