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

For Loops in PHP Forum

View Course » View Exercise

1032 points
418463ea876fbbaf0bc849c3b79360a3?s=140&d=retro
Submitted by
gavin barker
almost 4 years ago

Code seems ok but not working

here is what I put

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

  }
  ?>
but what I get is an error message
Oops, try again. Did you set the second part of your loop correctly (the part that ends the loop)? Don't forget your semicolon!

4 votes

permalink

My didn't work either until I commented out the for loop, refreshed the page, then removed the comment tag. This is my code that worked:
<?php
for ($i = 50; $i > 4; $i = $i - 5) {
echo $i;
}
?>

802 points
52eff2a052f8636b570014e6_463854577
Submitted by
David Lawter
almost 4 years ago

2 Comments

Fb816ef8e77efe98533a183b2d8b7d73?s=140&d=retro diana_pencheva almost 4 years ago

This worked for me too. Looks like the environment tries to execute in the time I still was correcting the code.

Picture Terry Mitchell almost 4 years ago

Same problem here.... Shoddy lesson.


2 votes

permalink

mine is the same and not working either same message

218 points
0d6845ebc23facbb73db9a85828b0084?s=140&d=retro
Submitted by
jharan
almost 4 years ago

3 Comments

0d6845ebc23facbb73db9a85828b0084?s=140&d=retro jharan almost 4 years ago

i got it to work by resetting the code and then first commenting out // the 'for' line ... while commented i adjusted it to for($i = 50; $i >= 5; $i = $i - 5) .. then finally take out the comment symbols // and that will fix it....

63bfe9dbda44b8c00b1688421be640a4?s=140&d=retro presquevu almost 4 years ago

Thanks for posting! Same issue - this worked for me too.

Da67f212204a1d8005ef88ac84ff11f2?s=140&d=retro yechielweb almost 4 years ago

Thanks it worked for me too!


0 votes

permalink

Hmmm Thanks! very strange but it does work

1032 points
418463ea876fbbaf0bc849c3b79360a3?s=140&d=retro
Submitted by
gavin barker
almost 4 years ago