Jump to content
Larry Ullman's Book Forums

for loop - how to escape infinite loop?


Recommended Posts

I just finished reading Chapter 6. As mentioned one should be careful not to have infinite loop but what if a mistake occurred how do we escape it?

As an example in Script 6.9 instead of

                <?php // Print out 31 dyas:
                for ($i = 1; $i <= 31; $i++) {
                    print "<option value=\"$i\">$i</option>\n";
                }
                ?>


it got written like // NOTE on "i--" instead of "i++"

                <?php // Print out 31 dyas:
                for ($i = 1; $i <= 31; $i--) {
                    print "<option value=\"$i\">$i</option>\n";
                }
                ?>

I'm using a real web hosting so I do not want to try it that could get me suspended. But if I did try it, what will happen to the web browser display and to the hosting server?

Link to comment
Share on other sites

If this does happen--and it may happen some day by accident--the web browser will just hang and never completely load the script (because the server is still running it). Simply close that browser tab! Something like this, while unnecessary, isn't actually a heavy burden on a web server. 

Link to comment
Share on other sites

Thanks for the nice words and for the interest in the books! I really appreciate it. I'd do those books in the opposite order, though. The PHP & MySQL has some overlap with this one, but goes into much greater detail, in more depth, and uses different examples. You'll probably want a bit more practice in before reading the Advanced book. Thanks again!

Link to comment
Share on other sites

 Share

×
×
  • Create New...