Let's step over what is happening:
$num1 = 10; // $num1 = 10, no issue
while ($num1 < 20) { // If $num1 is less than 20, do
// everything between { and }
echo $num1; // print the value of $num1 as it is
// at this point of time. Can only be
// in the range from 10 to 19
$num1++; // Increment the value of $num1 by 1
}
// Just for fun
echo $num1; // displays 20 as that is current value
// of $num1
At the echo $num1;, you will only ever see a maximum value of 19 due to the while statement $num1 < 20.
After you see the echo of 19, then $num1 will have a value of 20 as that is what the $num1++ says to do.
Alternatively, you could do the following to print the numbers from 11 to 20:
$num1 = 10; // $num1 = 10, no issue
while ($num1 < 20) { // If $num1 is less than 20, do
// everything between { and }
$num1++; // Increment the value of $num1 by 1
echo $num1; // print the value of $num1 as it is
// at this point of time.
// This will be in the range from
// 11 (not 10) to 20
}
// And finally for testing
echo $num1; // displays 20 as that is current value
// of $num1
$num1is less than 20 2.) Output the unmodified value of$num13.) Increment Either use<=instead of<or increment before you output the value (which i oppose to do since it becomes somewhat unclear in which cycle you are).