PHP learn -  Do While Loop

The difference between do...while and while is that their values ​​are checked at different timings.

Do-while Regardless of whether the while judgment is true, the code code block loop statement is executed once and guaranteed to be executed once (the true value of the expression is checked after each loop).
However, our while loop above will check the Boolean decision area and set it up. If it is not established, it will not be executed.

Example :

//executed code;

}while ( condition is true );

The following example first sets the variable $x to 1 ($x=1). Then, the do while loop outputs a string and increments the variable $x by 1. Then check the conditions

Check ($x is less than or equal to 5). As long as $x is less than or equal to 5, the loop will continue to run, anyway, the loop ends

Example :
 Header("Content-type:text/html;charset=utf-8"); //Set the encoding
 Do {
     Echo "This number is: $x <br>";
 } while ($x<=5);

This number is 1
This number is 2
This number is 3 
This number is 4 
This number is 5

Try this program on your computer .

Last Updated: 2018-07-06 12:32:44 By akshay


share_facebook share_twitter share_google_plus

Please Comment Here :