How to use while and do while loops in php

PHP

We will show you how to use do and do while loop in the php with the below examples. We need to initialize the variable and then we need to increment the variable by “++” or “–” signs. Then the statement will not be true the loop will move and move till the condition does not get match , when it matches it break the loop.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>WHILE and DO WHILE LOOP Examples in PHP</title>
</head>
<body>
<?php

//We initialise value of j as 1
$j=1;
while($j<=10)
{
// While loop will run for 10 times and it will print 1 to 10 with space of one line
echo "The Value of J will be -&nbsp; " . $j . "<br>";
//j++ means the adding one value to variable j
$j++;
}

$j=10;
while($j>=11)
{
// While loop will run for 10 times and it will print 10 to 1 with space of one line
echo "The Value of J will be -&nbsp; " . $j . "<br>";
//j-- means the deducting one value from variable j
$j--;
}

// Same way we can use do while loop for the above examples

$j=1;
do
{
$j++;
echo "The Value of J will be-" . $j . "<br>";
}
while ($j<=10);

$j=10;
do
{
$j--;
echo "The Value of J will be-" . $j . "<br>";
}
while ($j>=1);


?>
</body>
</html>
-->