Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Basic Control Structures in PHP

By Darren W. Hedlund
2005-06-20


Infinite loops

What would have happened if we had forgotten to include the increment of $count in the body of our while loop? The variable $count would have never been incremented and therefore would have never reached the value of 5. Because of this, the conditional $count <= 5 would always evaluate to true and the program would never leave the while loop. This situation, called an infinite loop, is a common mistake by many programmers. Be careful when using while loops (or any type of loop discussed) to ensure that the program will eventually terminate.

Note: PHP will not allow a program to run longer than a specific period of time (determined by the system administrator) without special settings. Usually the default settings give any reasonable script enough time to complete without premature termination. However, there are times when a processor-intensive script's running time exceeds the default maximum time. In these cases, please consult the PHP documentation for instructions on how to extend the run time from within your PHP scripts.

In my next article I will discuss with you a more specialized version of a while loop called a for loop, as well as the methods behind multi-condition if statements.



Tutorial Pages:
» Conditional blocks
» The if statement
» Basic looping
» The while statement
» Infinite loops
» Notes on embedding code blocks


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1