Home of web learners

www.webn3rd.com

Do while loop is also very special loop and for special purpose use

Lets look an do while loop example

<?php
$x = 0;
do{
echo $x;
$x++;
}while($i <= 3);
?>

output:

01234

Here,we see that $x=0 is iniialization part,its like while loop

Then loop start after do,no need to check condition to execute body part

In the body part,we show value of x

In body part we use increment or decrement as while loop,we use increment part by $x++

After one interation without check condition and execute body part,then after increment value,then now it check condition with new value of x after interation.

The thing in do while loop is if the condtion is false,but do while loop execute one times,where other loop don't execute if the condition is false

As php work up to down style,so the condtion is in last part,so it checks not for first time

webn3rd.com

About webn3rd