Monday, May 30, 2011

PHP - Do While Loop

A "do while" loop is a slightly modified version of the while loop. If you recal from one of the previous lessons on While Loops the conditional statement is checked comes back true then the code within the while loop is executed. If the conditional statement is false then the code within the loop is not executed.

A simple example that illustrates the difference between these two loop types is a conditional statement that is always false. First the while loop:

$cookies = 0; do {  echo "Mmmmm...I love cookies! *munch munch munch*"; } while ($cookies > 1);



Output : - Mmmmm...I love cookies! *munch munch munch*

No comments:

Post a Comment