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

For Loops in PHP Forum

View Course » View Exercise

382 points
514df45c1ca6a548ee0012c1_872043340
Submitted by
Asif Nawaz
about 4 years ago

Why not the code was accepted?

My section is "when to use for?"

<?php
for ($i = 50; $i > 0; $i = $i - 5) {
echo $i;
}
?>


4 votes

permalink

This worked for me.

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

1018 points
500fc062262f92000201c0c5_362527996
Submitted by
km
about 4 years ago


1 vote

permalink

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

299 points
Cf67d55abd75859eb419ca304be2f87d?s=140&d=retro
Submitted by
Garrett
about 4 years ago

3 Comments

514df45c1ca6a548ee0012c1_872043340 Asif Nawaz about 4 years ago

may be code academy bug, php section is new may be for this!!

Picture Todd Elliott about 4 years ago

I had this same code... it won't take it either.

Picture Fin Jones about 4 years ago

This is what I had, but above they stated to tack on a = with the -. So for($i=50; $i>=5; $i=$i-=5). Why?


1 vote

permalink

<?php
for ($i = 50; $i > 1; $i = $i -= 5) {
echo $i;

}

Solution

219 points
Picture
Submitted by
Evan Brenelus
about 4 years ago

4 Comments

514df45c1ca6a548ee0012c1_872043340 Asif Nawaz about 4 years ago

yes! it is working, but your code and my code was making same output I have tested in my locahost, why not it was accepted by codeacademy!!

Anyway thank you Evan!

Df8f468bef50e9fa2a14037955ff0e2e?s=140&d=retro ahmed ullah about 4 years ago

there are too many bugs. After you run this above code you can change your code to for ($i = 50; $i>=5; $i-=5) and it works.

514df45c1ca6a548ee0012c1_872043340 Asif Nawaz about 4 years ago

Ya, I am facing many fake error message, hope everything will fix soon

21b7455c40509786bbb7c95a43bcc6c6?s=140&d=retro Curtis Lea about 4 years ago

The code is fine, their website is having some Issues apparently.