php_loopsOver the last couple of weeks I have been writing blog posts about using PHP Loops. So now in total I have actually written five (5) posts explaining all about loops in PHP and how we use them.

So, I thought to myself why not release just one more blog post about PHP loops that clearly states what I have done and links them all together for anyone to easily reference from or to. :)

To start off with here is a basic overview of loops:

Loops, which are used frequently in program, set up a block of statements that repeat. Sometimes, the loop repeats a specified number of times. For instance, a loop to echo all the state capitals needs to repeat 50 times. Sometimes, the loop repeats until a certain condition exists.

Continue Reading ->



php_loopsSometimes you want your program to break out of a loop. PHP provides two statements for this purpose:

  • break: Breaks completely out of a loop and continues with the program statements after the loop.
  • continue: Skips to the end of the loop where the condition is tested. If the condition tests positive, the program continues from the top of the loop.

break and continue are usually used in a conditional statement. break, in particular, is used most often in switch statements.

Continue Reading ->



php_loopsYou can easily set up loops so that they never stop. These are infinite loops. They repeat forever. However, seldom does anyone create an infinite loop intentionally. :)

I know sometimes that I have personally had a mind lapse and placed the wrong statement within a while loop instead of outside the thing. Man that does your head in I tell you… ;)

If an infinite loops exists it most probably is a mistake in the programming. For instance, a slight change to the program that sets up a while loop can make it into an infinite loop.

Continue Reading ->



php_loopsA do..while loop is similar to a while loop. A do..while loop continues repeating as long as certain conditions are true.

You set up a condition. The condition is tested at the bottom of each loop. If the condition is true, the loop repeats. When the condition is not true, the loop stops.

This is my third blog post on using loops in PHP, so it you want to check out my other posts then please look at the bottom of this post to find the links to my other loop articles. :)

Continue Reading ->