August 2000
Intermediate to advanced
800 pages
13h 15m
English
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.
<? /* ** 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 */ ... |
Read now
Unlock full access