101Chapter 6Control and FunctionsA note on (Post office web site) infinite loopsIf

101Chapter 6Control and FunctionsA note on infinite loopsIf you ve ever programmed in another language, you ve probably had the experience of acci- dentally creating an infinite loop (a looping construct whose exit test never becomes true andso never returns). The first thing to do when you realize this has happened is to interrupt theprogram, which will otherwise continue forever and use up a lot of CPU time. But what doesit mean to interrupt a PHP script? Is it sufficient to click the Stop button on your browser? As it turns out, the answer is dependent on some PHP configuration settings you can setthe PHP engine to ignore interruptions from the browser (like the result of clicking Stop) andalso to impose a time limit on script execution (so that forever will only be a short time). The default configuration for PHP is to ignore interruptions, but with a script time limit of 30seconds the time limitation means that you can afford to forget about infinite loops thatyou may have started. For more on the configuration of PHP, see Chapter 30. Alternate Control SyntaxesPHP offers another way to start and end the bodies of the if, switch, for, and whilecon- structs. It amounts to replacing the initial brace of the enclosed block with a colon and theclosing brace with a special ending statement for that construct (endif, endswitch, endfor, and endwhile). For example, the ifsyntax becomes: if (expression): statement1statement2.. endif; Or: if (expression): statement1statement2.. elseif(expression2): statement3.. else: statement4.. endif; Note that the elseand elseifbodies also begin with colons. The corresponding whilesyntax is: while (expression): statementendwhile; Which syntax you use is a matter of taste. The nonstandard syntax is in PHP largely used forhistorical reasons and for the comfort of people who are familiar with it from the early ver- sions of PHP. We will consistently use the standard syntax in the rest of this book. Cross- Reference08
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply