While Loop and Do While Loop In PHP

while loop,do while loop,php loopsWhile Loop and Do While Loop In PHP are another most essential condition checker in php.

There is a difference between while loop & do while loop that is in do while loop a statement can be executed one time if  the given condition is false.But it is impossible in While loop.

Dear learner here you can learn how to use while and do while loop with proper example:

While Loop:

WHILE Loop is used in PHP to provide a control condition like for loop.

Syntax of While Loop:

While (condition expression)

{

[A statement that have to executed; ]

}

To get clear idea about while  loop see the following interface:

while loop

Example of While loop with  php code:

<html>
<body>

<?php
$j=1;
while($j<=3)
{
echo "Condition is true when value of j is: " . $j . "<br>";
 $j++;
}
?>

</body>
</html>

The output of the above code :

Condition is true when value of j is: 1
Condition is true when value of j is: 2
Condition is true when value of j is: 3

Do while Loop:

DO WHILE Loop is used in PHP to provide a control condition Like While Loop.

Syntax of do while loop:

do

{

[a statement that have to execute write here;]

[increment/decrement variable if you want to use it;]

} while (condition checking statement)

To get clear idea about do while  loop see the following interface:

do while loop

Example of While loop with  php code:

<html>
<body>

<?php

$j = 7;
DO {
 echo "The value of j after 1 decrement: " . $j . "<br>";
$j--;
} WHILE ($j > 4);

?>

</body>
</html>

The output of the above code is:

The value of j after 1 decrement: 7
The value of j after 1 decrement: 6
The value of j after 1 decrement: 5

Related Post:

Comments

  1. says

    AMD to bid goodbye to ATI branding,Discount Oakley Sunglasses On SaleWays to rumored,Wholesale Discount Oakley Sunglasses, And it is true. One of the halcyon brands of the PC video card industry is getting ready to be retired. AMD,Discount Oakley Sunglasses Sale, Which ordered ATI in 2006, And which has maintained the brand for its graphics missions, Will quickly kill it.The reasons are believed to be varied, But does include internal investigation by AMD. While the details of the published rese