简体   繁体   English

基本的PHP概念/语法

[英]Basic PHP concept/syntax

I'm new to PHP and below is one of my first codes that I have tried, for understanding the basic concept and syntax. 我是PHP的新手,下面是我尝试的第一批代码之一,用于了解基本概念和语法。 I'm running the code using XAMPP server. 我正在使用XAMPP服务器运行代码。

<?php
$var=1;
while($var<10){
    if($var==2) continue;
              echo "$var <br>";
$var++;
  }
?>

I'm getting the following error :- 我收到以下错误:

1 1个

Fatal error: Maximum execution time of 30 seconds exceeded in C:\\xampp\\htdocs\\day\\BreakDemo.php on line 4 致命错误:第4行的C:\\ xampp \\ htdocs \\ day \\ BreakDemo.php中超过30秒的最大执行时间

Why does it throw the error ? 为什么会引发错误?

因为,当$var将为2 ,您说, continue ,然后移动下一个迭代,因此从那时起,这将是一个无限循环,并且$var再也不会拥挤了。

You have an infinite loop. 您有一个无限循环。 If you do it by hand here is what happen: 如果您手动操作,则会发生以下情况:

  • var = 1
  • var == 2 ? NO
  • echo var
  • var++ // var=2
  • loop
  • var == 2 ? YES
  • continue
  • loop
  • var == 2 ? YES
  • ... ...

You have to increment $var before the continue to escape the infinite loop. 您必须先递增$var才能continue逃脱无限循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM