O'Reilly logo

Core PHP Programming: Using PHP to Build Dynamic Web Sites 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

The do...while Statement

You can delay the decision to continue executing a loop until the end by using a do...while statement. Listing 3.8 retools Listing 3.7. You won't notice a difference unless you run the script on a Friday. On Fridays the original will print nothing in its list of days. The new version will put Friday in the list because the body of the loop is executed before currentDate is tested. By switching to a do...while loop, the loop now lists the days until next Friday.

Listing 3.8. Using do...while to Print Day Names
 <? /* ** get the current date in number of seconds */ $currentDate = time(); /* ** print some text explaining the output */ print("Days left before next Friday:\n"); print("<OL>\n"); do { /* ** print day name */ ...

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