English
German

PHP Do While

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.

On the other hand, a do-while loop always executes its block of code at least once. This is because the conditional statement is not checked until after the contained code has been executed.


PHP While Loop and Do While Loop Contrast

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

Example:

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

As you can see, this while loop's conditional statement failed (0 is not greater than 1), which means the code within the while loop was not executed. Now, can you guess what will happen with a do-while loop?


PHP Tutorial,PHP Do While, PHP Do While example, learn PHP Do While,explain example PHP Do While online free training PHP Tutorial, PHP Tutorial example, learn PHP Do While, online tutorial, download tutorial, PHP Tutorial books, PHP Tutorial videos, live videos PHP Tutorial, learn PHP Tutorial, PHP Tutorial topic PHP Do While, live training PHP Tutorial, download free tutorial