PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

Loop Statements - "while", "for", and "do ... while"

This free PHP tutorial book is a collection of notes and sample codes written by the author while he was learning PHP himself. It can be used as a tutorial guide for beginners or a reference book for experienced developers. Topics include PHP, array, CGI, CLI, session, cookie, database, directory, file, HTTP, header lines, IIS, image, mail, MySQL, redirect, request, response, SMTP, SOAP, SOAP Extension, SQL, Unicode, WSDL.

"while" Statements

"while" Statement Examples

"for" Statements

"for" Statement Examples

"do ... while" Statements

"break" and "continue" Statements

Conclusion:

  • "while" statement is the most commonly used loop statement in PHP.
  • "for" statement is the most complex loop statement in PHP.
  • "do ... while" statement is just a variation of "while" statement.
  • "break" statement takes an optional parameter to break multiple level of loops.
  • "continue" statement takes an optional parameter to break and continue on the specified level of loops.

Dr. Herong Yang, updated in 2009
Loop Statements - "while", "for", and "do ... while"