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

For Loops in PHP Forum

View Course » View Exercise

574 points
55be1a6f9113cbbc23000167_279851225
Submitted by
Hrvoje Verić
almost 4 years ago

[resolved] Got the code right, but can't proceed on to the next excercise

Here's the code:

<?php
for($i = 10 ; $i <= 100 ; $i = $i + 10){
echo $i;
}
?>
When I hit "Save & Submit Code" button, I get
"Oops, try again! Did you set the first part of your loop correctly (the part that starts the loop)? Don't forget your semicolon!"


7 votes

permalink

This lesson doesn't seem to like spaces. Try this;

<?php
   for($i = 10; $i <= 100; $i = $i + 10){
    echo $i;
    }
  ?>

229 points
D8411dbf9e35ee9dcd08e121a975e914?s=140&d=retro
Submitted by
zjay
almost 4 years ago

2 Comments

15971c584f3c4000fb7c7e2fbe34b2cf?s=140&d=retro GAURAV BISHT almost 4 years ago

i tried that but the problem is not solving.....

8c63f698f8ca6382ecbf230993dc0036?s=140&d=retro interglobalmedia almost 4 years ago

What you have to do is treat 10 as if it were 1.

So $i < 110;


3 votes

permalink

hey just got it .... u just refresh the page and then submit the code it will work....

382 points
15971c584f3c4000fb7c7e2fbe34b2cf?s=140&d=retro
Submitted by
GAURAV BISHT
almost 4 years ago

2 Comments

Picture Thomas Gam Nielsen almost 4 years ago

I had to switch browser from Google Chrome to Firefox to get it working...

12593c1427fc040772e466c67e938636?s=140&d=retro cannibalwithcutlery over 2 years ago

apparently firefox is broken too lol.... oh my gosh :O

When I finally understand... it just won't load and my code is right.... ik the browser crashes but any other time i've worked with for loops and it can work (for loops for diff . languages)


1 vote

permalink

for($i = 10; $i <= 100; $i = $i + 10 ){
    echo $i;
    }

this is the code :D .. try it.. maybe look same but dif

347 points
52bea88b9c4e9de4c30052e0_803424050
Submitted by
Yolo-D-Nandos
almost 4 years ago

1 Comment

Picture Aaron Weiss almost 4 years ago

This passes. Using $i < 101 as the second element in the for loop causes it to fail, even though the result is correct. Sounds like a bug in the SCT.


0 votes

permalink

Tried all suggestions but to no avail. :/

574 points
55be1a6f9113cbbc23000167_279851225
Submitted by
Hrvoje Verić
almost 4 years ago

1 Comment

15971c584f3c4000fb7c7e2fbe34b2cf?s=140&d=retro GAURAV BISHT almost 4 years ago

try doing as suggested and if it does not work then refresh page and submit it will do the work


0 votes

permalink

Erasing the comment in the code helped, now it works. :)

574 points
55be1a6f9113cbbc23000167_279851225
Submitted by
Hrvoje Verić
almost 4 years ago


0 votes

permalink

Not putting a space between the curly brace and the parentheses really helps.

1970 points
501bf5bd0a4630000203ea40_415622017
Submitted by
Joshua Marsden
almost 4 years ago


0 votes

permalink

No you replace echo to print

1783 points
52923321abf82138c20059f8_562129230
Submitted by
Caladbolg
almost 4 years ago