简体   繁体   中英

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. I'm running the code using XAMPP server.

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

I'm getting the following error :-

1

Fatal error: Maximum execution time of 30 seconds exceeded in C:\\xampp\\htdocs\\day\\BreakDemo.php on line 4

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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