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

For Loops in PHP Forum

View Course » View Exercise

675 points
52205001f10c604a1b001776_776985269
Submitted by
superbear
over 4 years ago

have a trobule at Writing Your First 'For' Loop

    Go ahead and write a for loop that echos the numbers 10 up to and including 100, counting by 10s (e.g. 10, 20, 30...).

    I code like this,bu it not works.
  <?php
  // Write your for loop below!
  for($i = 0;$i < 101;$i = $i + 10){
      echo $i;
  }
  ?>

1 vote

permalink

From your code
There is a mistake -----> for($i = 10 ;
instead you wrote ------>for($i = 0 ;

My code and yours is same ,check mine below :

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

741 points
3aa413fab5f1df952a96b20c6eaa5a09?s=140&d=retro
Submitted by
aboki
over 4 years ago

1 Comment

52205001f10c604a1b001776_776985269 superbear over 4 years ago

Thank you!


0 votes

permalink

I was having the same issue with it; as I was typing " $i = $i + 10 " it gave me the infinite loop error as soon as I'd typed $i = $i ... giving the error before I could add the + 10.

Instead I wrote the code in another window and pasted; worked fine. I'm assuming this has to do with it constantly updating the preview and checking your code.

267 points
90cfc999d7b2ae12528598321dba8a77?s=140&d=retro
Submitted by
John Tate
over 4 years ago

2 Comments

52205001f10c604a1b001776_776985269 superbear over 4 years ago

It may be someting bad.

52205001f10c604a1b001776_776985269 superbear over 4 years ago

and It can't pass with error.


0 votes

permalink

I have the same code, however I keep getting "Parse error: syntax error, unexpected ')', expecting ';' on line 9" I have verified everything. what am I missing?

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

84 points
A1998b166d1f20d99e5a2ee1564c811d?s=140&d=retro
Submitted by
David Bird
over 4 years ago

6 Comments

52205001f10c604a1b001776_776985269 superbear over 4 years ago

$i < 101;when the loop end,the $i value is 100.

Fc67aac953c6a2fa0d984b22072f94fd?s=140&d=retro spadge77 over 4 years ago

it still doesn't work

Fc67aac953c6a2fa0d984b22072f94fd?s=140&d=retro spadge77 over 4 years ago

there is dam error with this part it doesn't work


Solo For Loop!



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



i have tried every single way

52205001f10c604a1b001776_776985269 superbear over 4 years ago

$i += 10 or $i = $i + 10

52205001f10c604a1b001776_776985269 superbear over 4 years ago

try

Fc67aac953c6a2fa0d984b22072f94fd?s=140&d=retro spadge77 over 4 years ago

it works now :o


0 votes

permalink

I found I had to "comment out" my for loop until I finished typing it, then removed the comment marks, and it worked.

259 points
51bb72297c82caa968001745_583186607
Submitted by
Sandi Jones
about 4 years ago


0 votes

permalink

it's complaining about foreach.........

334 points
D43c52d0d8927f301ebcde3ab1aaa416?s=140&d=retro
Submitted by
Perry Venema
about 4 years ago