Home Tutorial Php Phpbeginners while & do..while Loop

 
 

while & do..while Loop
Posted on: February 5, 2011 at 12:00 AM
Advertisement
This section contains the detail about while & do..while Loop in PHP.

while & do..while Loop

while loop

The while loop iterate until provided condition is true. Given below the syntax :

while (condition)
  {
  code to be executed;
  }

Example

<html>
<body>

<?php
$j=1;
while($j<=3)
{
echo "Value of j" . $j . "<br />";
$j++;
}
?>

</body>
</html> 

Output :

Value of j 1
Value of j 2
Value of j 3

The do...while statement

The do-while loop always executes its block of code at least once. Given below the syntax :

do
  {
  code to be executed;
  }
while (condition);

First it executes code and then checks the condition. It it is true, then loop iterate through further. Given below the example :

Example :

<html>
<body>

<?php
$j=1;
do
{
$j++;
echo "Value of j" . $j . "<br />";
}
while ($j<=3);
?>

</body>
</html>

Output :

Value of j 2
Value of j 3
Value of j 4

Advertisement

Related Tags for while & do..while Loop:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 5, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com