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

For Loops in PHP Forum

View Course » View Exercise

1163 points
D7d028b6b1039aceac6185600a75c81c?s=140&d=retro
Submitted by
MattMogram
about 4 years ago

ATTN CODECADEMY - There is a problem with PHP lesson 1.4 When to Use 'For'

Sometimes it runs and gives me an error message even when I have not pressed submit.

But more importantly, it is not accepting code that should work. Here is the code I have entered:

    <html>
  <head>
    <title>Solo For Loop!</title>
  </head>
  <body>
    <p>
      <?php
      // Write your for loop below!
    for($i = 50; $i > 4; $i = $i-5) {
        echo $i;
    }  
      ?>
    </p>
  </body>
</html>

Does anyone see any reason that would not work? I am almost positive it should work but since I am still learning, perhaps I have missed something.

If it should work, then there is a problem with this lesson and it needs to be fixed.


8 votes

permalink

I was having a similar problem. My code was slightly different from yours:

for ($i = 50; $i > 1; $i = $i -= 5) {
echo $i;
}

Instead of $i > 4, I wrote $i > 1, but that was just a personal choice. I had to change the last part to -= 5 from -5. I saw the suggestion from another member on this same thread and it worked. But we weren't shown this way previously. They didn't show this method in the previous lessons or Hints. I think the Codeacademy people are working on fixing this bug. Hope this works for you in the meantime.

197 points
5875baec7e1e3563412d0a6b0740419f?s=140&d=retro
Submitted by
hl9
about 4 years ago

2 Comments

E0b030f7c74ebb566613215b0f9b5cf1?s=140&d=retro Dinesh Jain about 4 years ago

Thanx i was stucked at this part too

C59c586715fb1e37207a494bb0e45c1e?s=140&d=retro seejaeger about 4 years ago

isnt it supposed to be $i >=5 though????


8 votes

permalink

Just got this to work:

<html>
  <head>
    <title>Solo For Loop!</title>
  </head>
  <body>
    <p>
      <?php
      // Write your for loop below!
        for ($i = 50; $i > 1; $i -= 5) {
            echo $i;
        };
      ?>
    </p>
  </body>
</html>

977 points
51295c9cbd8239b8f10007e4_566182898
Submitted by
Kyle Shevlin
about 4 years ago

5 Comments

83707b2f56fd7ed026cfdf6f0dac24b3?s=140&d=retro khalid about 4 years ago

I wrote

<?php
// Write your for loop below!
for ($i = 50; $i > 0; $i =$i- 5) {
echo $i;
};
?>
and got same result but didn't accepted.Why?/please advise me.

Picture Kai Smash about 4 years ago

It passes with : $i - =5 )

6fa21866b3409991ddcea0daba5bf4ab?s=140&d=retro qkcode about 4 years ago

Same here; worked with $i -= 5,but did not with $i = $i - 5

510bf8724eb5c0de6f000e64_898509885 Julio Polo™ about 4 years ago

This one worked for me, but i < 4 or i<= 5 should work too, what's going on?

9a9eca1f8eed759a023aa08e4f9f8931?s=140&d=retro macmesser about 4 years ago

Same problem here. I tried $i > 4 and $i > = 5 and got errors. "Code takes too long, check for infinite loop (or something like that). Apparently a problem with this one, but it doesn't allow mw to advance to the next one.


0 votes

permalink

If you try pasting their example code in it also times out so what chance do we have!

1368 points
50728b57ab8352b0f245b6442995bff1?s=140&d=retro
Submitted by
John Pill
almost 4 years ago

1 Comment

504596100bd4d6000202f027_107871597 Ryan almost 4 years ago

Had the exact same problem, right code, infinite loop. Switched from using chrome to firefox, works on firefox. These things happen. As a web dev you soon learn that cross browser compatability is where you will spend a good chunk of your time.


0 votes

permalink

I'm having serious problems with this excersise also, can i receive some help, please.

264 points
0dfb506703fdbb82a0bb7db55628e25d?s=140&d=retro
Submitted by
Fede Riveros
almost 4 years ago

1 Comment

5331647e9c4e9d8150001c7c_569846834 derick felix about 3 years ago

i need some explanation please any one...


0 votes

permalink

Amazing, I can't get through this lesson at all.... Every loop I try to write it says: "Did you forget (..)".
The bloody loop should work, I already got it to work in notepad++

<?php
for ($i = 0; $i < 101; $i = $i + 10) {

    echo $i;

    }

  ?>

139 points
A15ba3c740ddfc3053e826c29c960514?s=140&d=retro
Submitted by
Shdow89
over 2 years ago