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

For Loops in PHP Forum

View Course » View Exercise

476 points
3a3a862dcfe200839470bd6b7e41be89?s=140&d=retro
Submitted by
Ralph
about 4 years ago

I think that you need to rewrite this section

Why does this not work? You need to rethink your code in the for loop section.
<?php
// Write your for loop below!
for ($i = 50; $i >= 5; $i = $i - 5) {
echo $i;
}
?>


11 votes

permalink

Yes, editing the code from the previous exercise generates an error. I had the same experience, until I eventually deleted the previous code and coded specifically for this exercise.

Note to Codecademy: this does need to be rectified. I'm sure I'm a lot of people, like me, may have wasted valuable time trying to figure out what they were doing wrong.

Either configure the console to accept changes to the code from the previous exercise or (even better), erase the code from the previous exercise.

Here's my code for the exercise:

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

777 points
5198aefe94cf37ba2900070c_9511443
Submitted by
Simon Latham
almost 4 years ago

4 Comments

51957f69fe8c9bd9900003f5_92013663 Bong Anceno almost 4 years ago

Passed the section only after copying and pasting the code above. This is a very serious parser problem.

Picture oladan over 3 years ago

i had the same problem....Passed after using your code Simon! Thanks mate

Picture wilsondc over 3 years ago

I've had several issues with code I know works but will not pass test here. Who ever is writing the code for this needs to realize that there is more than one way to code and it be correct.

E93743867af744f1c0aeb592f98137e4?s=140&d=retro 张鑫 over 3 years ago

thanks i didn't pass this section until i updated my code with yours!:)


2 votes

permalink

That should work. That was what I used in my code and it worked just fine. Here is what I used:

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

538 points
36e2a4e14b39a0b585c7844886d24ab5?s=140&d=retro
Submitted by
Anthony Armfield
about 4 years ago

4 Comments

53f3764e282ae3da53000455_587160470 Julijana Seketa almost 4 years ago

You should maybe put an explanation with your code to help other users what they did wrong and so they understand.

Df2d4b54adbc84b9d6b35d257dd71aac?s=140&d=retro Caki_51c076b27c82ca27ab00e714_delete almost 4 years ago

You saved my life. Thank you. I was getting eternally stuck.

51d3095c631fe99d8300f1ee_28136572 Laurent Frileux almost 4 years ago

thanks a lot it worked

B9b4af7d293f8c94db1d696f5a21fc1e?s=140&d=retro D. Philpot over 3 years ago

thanks for the help, i no i was right with the original code i wrote but since i passed with your code ill take it


2 votes

permalink

I agree that Codecademy needs to get these bugs fixed! I am trying to learn the program not troubleshoot system errors.

This was being discussed a month ago - it should be resolved by now.

702 points
89cff153f021e1fdb4115b1870179fcd?s=140&d=retro
Submitted by
Lisa
almost 4 years ago


1 vote

permalink

I think that I see the issue. When there is an error, the code needs to be reset. It will not run until it is reset. This includes errors from the previous question. You may need to work on your UI a little.

476 points
3a3a862dcfe200839470bd6b7e41be89?s=140&d=retro
Submitted by
Ralph
about 4 years ago


0 votes

permalink

This is mine,

for($i=50;$i > 1; $i-=5){
          echo $i."<br>";
      }

:)

603 points
E10c5b740e9886521949846c823accaf?s=140&d=retro
Submitted by
karen barreto
about 4 years ago


0 votes

permalink

These buggy excercises are annoying and a really demotivating. That we're not able to save a certain state of code (like in the past) and everything is done automatically (and wrong!) doesen't help either ...
Here I had to copy and quickly hit the button to avoid the quick (and wrong!) error message which didn't let me do anything to pass the test. :((

1994 points
508c673ba0e5800200000d0b_564883382
Submitted by
Marcus
almost 4 years ago


0 votes

permalink

The code seems to run before pressing the submit button. For this reason, I created an infinite loop before I had the chance to finish writing my code. The solution was to write the code in an outside editor and then paste it in all at once.

1509 points
612b26a220a1efefd0d96e861467b283?s=140&d=retro
Submitted by
Paul Bartsch
almost 4 years ago