Perl 编程 : continue block

标签 perl for-loop while-loop continue

我刚开始学习 Perl 脚本语言,有一个问题。

在 Perl 中,具有 continue 的逻辑原因是什么?与 while 一起阻止工作和 do while循环,但不是 for环形?

最佳答案

来自 http://perldoc.perl.org/functions/continue.html

If there is a continue BLOCK attached to a BLOCK (typically in a while or foreach ), it is always executed just before the conditional is about to be evaluated again, just like the third part of a for loop in C.



意思是在 for循环,第三个参数是 continue 表达式,例如for (initialization; condition; continue) ,因此不需要。另一方面,如果您使用 forforeach样式,例如:
for (0 .. 10) {
    print "$i\n";
} continue { $i++ }

这将是可以接受的。

关于Perl 编程 : continue block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5963286/

相关文章:

python - 如何从 perl 调用的 python 传递字符串?

perl - 在 Perl 中使用拆分和修剪进行映射

perl - 在运算符(operator)预期的位置找到了裸字

python - 如何用for循环影响列表的显示?

python - .readlines()[n] 错误

Perl:将子标准输出通过管道传输到父进程

每个函数中的 Javascript 新对象没有像我想象的那样工作

C# 计算循环中传递的数字数量

php - 如何像 Wordpress 循环一样制作我自己的 while 循环?

c - 为什么“while(!feof(file))”总是错误的?