| Control Structure : while
& do while loop compared |

|
|
while : loop watch before then enter |
<?php //get the current date in number of seconds $currentDate = time();
//print some text explaining the output print("Days left before Friday:\n"); print("<ol>\n"); while(date("l", $currentDate) != "Friday") { //print day name print("<li>" . date("l", $currentDate) . "</li>\n");
//add 24 hours to currentDate $currentDate += (60 * 60 * 24); } print("</ol>\n"); ?>
|

|
|
do while loop : jump first then decide, exit at-last |
<?php /* ** 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 */ print("<li>" . date("l", $currentDate) . "</li>\n"); /* ** add 24 hours to currentDate */ $currentDate += (60 * 60 * 24); } while(date("l", $currentDate) != "Friday"); print("</ol>\n"); ?>

|
| |
| |