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

For Loops in PHP Forum

View Course

595 points
3449d7a5aa36d6c2cd0a6a40aacc058a?s=140&d=retro
Submitted by
Lain666
almost 2 years ago

What is wrong with this code? 3/7

Solo For Loop!



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

When I click full screen, I get this result: 0102030405060708090100, but when I click Save & Submit I get an error: Oops, try again. Please follow the instructions on the Full Preview page to test your code.


1 vote

permalink

the issue is your statement that should be $i = 10, but you start at 0, so that why get an error message.

45 points
35f67eb2386d9aba205ae9294e5a0443?s=140&d=retro
Submitted by
Daniel Wang
almost 2 years ago


0 votes

permalink

Easy blunder to accomplish---believe me, you're far from the first.
In your echo statement use paragraph, break, or header tags, i.e.;
echo "$i"; or echo"$i "; or, if you want a readable format on the same line you could always use echo "$i  ";
Don't forget the semi-colon at the end of  

72 points
4f37f79550a58d36a77b935276e45f6a?s=140&d=retro
Submitted by
typomaniac101
almost 2 years ago

2 Comments

Picture Belarmino Nicolau Monteiro Simão almost 2 years ago

Thanks you very much, it works ...

51c14e598c1ccc92c1006609_222499189 Amrita Khurana Matta almost 2 years ago

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