PHP 继续语句
当阅读一本 PHP 书籍时,我想尝试我自己的(继续)示例。 我编写了以下代码,但它不起作用,尽管一切似乎都正常
$num2 = 1;
while ($num2 < 19)
{
if ($num2 == 15) {
continue;
} else {
echo "Continue at 15 (".$num2.").<br />";
$num2++;
}
}
输出是
Continue at 15 (1).
Continue at 15 (2).
Continue at 15 (3).
Continue at 15 (4).
Continue at 15 (5).
Continue at 15 (6).
Continue at 15 (7).
Continue at 15 (8).
Continue at 15 (9).
Continue at 15 (10).
Continue at 15 (11).
Continue at 15 (12).
Continue at 15 (13).
Continue at 15 (14).
Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/php/continueandbreak.php on line 20
第 20 行是该行
if ($num2 == 15) {
您能告诉我我的示例有什么问题吗? 我很抱歉提出这样的菜鸟问题
When reading a PHP book I wanted to try my own (continue) example.
I made the following code but it doesn't work although everything seems to be ok
$num2 = 1;
while ($num2 < 19)
{
if ($num2 == 15) {
continue;
} else {
echo "Continue at 15 (".$num2.").<br />";
$num2++;
}
}
The output is
Continue at 15 (1).
Continue at 15 (2).
Continue at 15 (3).
Continue at 15 (4).
Continue at 15 (5).
Continue at 15 (6).
Continue at 15 (7).
Continue at 15 (8).
Continue at 15 (9).
Continue at 15 (10).
Continue at 15 (11).
Continue at 15 (12).
Continue at 15 (13).
Continue at 15 (14).
Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/php/continueandbreak.php on line 20
Line 20 is that line
if ($num2 == 15) {
Would you please tell me what's wrong with my example ?
I am sorry for such a Noob question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果在
continue
之前不增加$num2
,您将陷入无限循环;if you don't increment
$num2
before thecontinue
you will get into an infinite loop;您甚至不需要继续那里,您的代码相当于;
如果这不是您想要实现的目标,那么您使用的 continue 方法是错误的。
You don't even need continue there, your code equivalent to;
If that's not what you're trying to achieve, you're using continue wrong.
在 php 中,使用 foreach 表示数组,使用 for 表示循环
in php, use foreach for arrays and for for looping