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

For Loops in PHP Forum

View Course » View Exercise

471 points
A9dfb070bdb9bb7f62d3340eeaf0444b?s=140&d=retro
Submitted by
fields_e
over 4 years ago

04/07 When to use "for"

I've done as instructed, I've managed to echo the correct loop from 50 down to 5, going down by 5s - it even shows up on the white box when I click save and submit, but an error keeps popping up about me forgetting a semi-colon! I do not see where or why this keeps popping up.

My code:
<?php
// Write your for loop below!
for ($i = 50; $i > 0 ; $i = $i - 5 )
{ echo $i; }
?>

The white box shows:
5045403530252015105

Error:
"Oops, try again! Did you set the second part of your loop correctly (the part that ends the loop)? Don't forget your semicolon!"


0 votes

permalink

Actually I saw where my mistake was now - I had no idea the ; had to hug the number in the middle command:

$i = 0; (I didn't realise it couldn't be loose ie. $i = 0 ; )

471 points
A9dfb070bdb9bb7f62d3340eeaf0444b?s=140&d=retro
Submitted by
fields_e
over 4 years ago


0 votes

permalink

Solo For Loop!



<?php
// Write your for loop below!
for ($i = 10; $i < 101; $i = $i + 10) {
echo $i;
}
?>

167 points
Picture
Submitted by
namit2saxena
over 4 years ago