Thursday, November 7, 2013

DO WHILE Statement in PHP

This statement is a modified form of the WHILE. The syntax is as follows

do
{
  statement;
  .
}
while (requiremet)

Compare this to the previous WHILE syntax. Judging from the position statement is repeated, position statement that is repeated on the DO WHILE located above terms. Thus, before the condition is checked its TRUE or FALSE, the statement will be done first. While on WHILE, before repeated statements done, first requirement will be checked.

DO WHILE working principle is similar to the WHILE statement will continue to be done during
condition evaluates to TRUE and FALSE when the loop will stop.

Consider the following example that compares with a DO WHILE WHILE

example:
<?
$kue = 0;
while($kue > 1)
{
  echo "I..Love you..";

?>

<?
$kue = 0;
do 
{
  echo "I..Love you..";
} while ($you > 1);
?> 

WHILE on the code, the text "I...." etc. will not be displayed because the condition is directly FALSE value (iteration stops). While the DO WHILE, the text will be displayed first and then looping stopped (FALSE value terms).

No comments:

Post a Comment