This forum is now read-only. Please use our new forums at discuss.codecademy.com.

While Loops in PHP Forum

View Course » View Exercise

878 points
453121cf174b2cef4b6c70ced3d59c7c?s=140&d=retro
Submitted by
leahael
over 2 years ago

Why does 7 show up if $x<=6 ?

Hi,
Having a bit of trouble: This is my code; Why does the code display 7 if X is less than or equal to 6?

<?php
//Add while loop below
$x = 0;
while($x<=6):
{
echo "here we go";
$x++;
echo "$x";
}
endwhile;
?>


0 votes

permalink

becasuse you put the $x++ before the echo so when the x value become 6 the code add 1 to it and become 7 and echo it

delet the { }

633 points
29c4d98821b0c2083f3a14771797842c?s=140&d=retro
Submitted by
jidd6
over 2 years ago

1 Comment

453121cf174b2cef4b6c70ced3d59c7c?s=140&d=retro leahael over 2 years ago

Oh that was helpful. Thanks!!