when you try this code the result is … The number is 1
<?php
$i=1;
do
{
echo "The number is " . $i . "<br />";
$i++;
}
while ($i==10);
?>
but when you change this code to be like this the result is 2
<?php
$i=1;
do
{
$i++;
echo "The number is " . $i . "<br />";
}
while ($i==10);
?>
so why the result changed ..?
$i++; is
post increment operator so it will increment value by 1 on next lineand it use same value on current lineFirst Case: you are doing echo $i and then doing increment
Second Case: you are incrementing $i++ before echo statement so by nature it will increase value by 1 on echo line