Hi All,
I am taking an online intro PHP class and am having a hard time understanding why the following two statements don’t output the same thing. The While loop outputs 0. 1. 2. 3. 4. FIVE 6. 7. 8. 9. 10. including the string “FIVE” as I expected, but the for loop does not. Instead it outputs 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .10 .11 Following are the two statements. Any help would be great because I am missing something super obvious.
While Loop:
<?php
$count = 0;
while ($count <= 10) {
if ($count == 5) {
echo “FIVE”;
echo “<br />”;
} else {
echo $count . ". ";
}
$count++;
}
?>
FOR Loop:
<?php
for ($count=0; $count <= 10; $count++) {
echo $count . " .";
} if ($count == 5) {
echo “FIVE”;
echo “<br />”;
} else {
echo $count . ". ";
}
?>
Jim