O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3.4. Loops

Loops allow you to repeat lines of code based on some condition. You might want to read lines from a file until the end is reached. You might want to print a section of HTML code exactly ten times. You may even wish to attempt to connect to a database three times before giving up. You may want to read data from a file until there's no more data to read. You can do all of these things with loops.

Each execution of the code inside a loop is an iteration. Loops iterate on the code until a stop condition is met. PHP supports four types of loops that vary from each other in what they iterate on, the actions taken before the loop begins, and whether the stop condition is checked at the beginning of each iteration or at its end.

The while ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required