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

For Loops in PHP Forum

View Course » View Exercise

638 points
5554e26151b8871c170001bc_960885506
Submitted by
陳虹積
over 2 years ago

I don't know where I make mistake

<?php
// Write your for loop below!
for ($i = 0 ; $i <= 100 ; $i+=10) {
echo $i;
}
?>

and it shows the wrong message :Did you set the first part of your loop correctly (the part that starts the loop)? Don't forget your semicolon!


0 votes

permalink

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

272 points
8e58e427a2372d6f10eb0ee3a4106c4c?s=140&d=retro
Submitted by
Lasowski
over 2 years ago


0 votes

permalink

I had the same problem: the code was correct but it still would not work. What helped me was to delete the entire code and rewrite it ( press the "Reset code" button ). I imitated the example as much as I could.

for[spacebar($i[spacebar]=[spacebar]0;[spacebar]$i[spacebar]<=[spacebar]100;[spacebar]$i[spacebar]+=[spacebar]10)[spacebar]{[return]echo $i;[return]}

As confusing as the above looks, the code should look like below:

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

P.S.
Just push the "Reset code" button.
After going through all this trouble I tried different spacing where I could and it still worked!
Try it for yourself. Although you should practice proper formatting and commenting to make your code readable, the below still works.

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

820 points
1518e310fdf23c9b9cccc3d9a75ed33e?s=140&d=retro
Submitted by
tchacon5
about 2 years ago


0 votes

permalink

didn't worked for me... in chrome.. in IE the same code did work..

<?php
// Write your for loop below!
for($i = 10; $i < 101; $i = $i+ 10) {
echo $i;
}
?>

233 points
F00fd9eca169bd710d31ee921a572eb2?s=140&d=retro
Submitted by
LorumIpsum
about 2 years ago


0 votes

permalink

I am experiencing the something similar. Also, half way through writing the code, i get an error pop up that says i am dealing with a infinite loop, yet i had not finished the code.

and when i click to submit, i never get a response to whether it is working. My code below & any help would be great!:

<?php
// Write your for loop below!
for ($i = 0; $i < 101; $i = $i + 10) {
echo $i;
}
?>

562 points
552c866286f552f0d40000f3_406724908
Submitted by
Brian
about 2 years ago

1 Comment

1518e310fdf23c9b9cccc3d9a75ed33e?s=140&d=retro tchacon5 about 2 years ago

I tried your code by cut and paste, and it worked great. I'm using the chrome browser. Did you try to: copy your code| Press the reset button at the bottom of the screen | Paste your code. If that does not work try either changing or updating your browser. Those are just guesses, but I hope it works.