For Loop tutorial issues


#1

https://www.codecademy.com/courses/web-beginner-en-L83Do/0/3?curriculum_id=5124ef4c78d510dd89003eb8

I have written my code exactly as instructed and after checking the example, I can see my code is correct.

However, when I attempt to submit my code as instructed, I am either told there is an infinite loop (looking at the code, there clearly isn't, and an old thread with this issue showed the same). Or, I subject to infinite validation that never completes, meaning I am now stuck on this tutorial.

I have seen similar issues with a failure to validate the code on numerous occasions on this course but refreshing the page usually sorted that out. I have now been stuck for 20 minutes while this page fails to complete. As I'm not the first to report this I assume it's an issue with the tutorial itself and not my code!


<?php
       for ($i = 0; $i < 101; $i = 10) {
           echo $i;
       }
       ?>


#2

Of course, I now see the issue in my code. Apologies!


#3

and you would be wrong. There is a problem with your code. this bit:

$i = 10

you set $i to 10, so each run $i will be set to 10, will you should increase $i with 10.

This way, your condition: $i < 101 can become false at some point (loops run until the condition is false)


#4

Yep, I spotted it as soon as I pressed submit on here.

That said, I have submitted the code and I'm still seeing infinite validation.


#5

can i see an updated version of your code?


#6

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


#7

that will just temporary add 10 to $i, you really need to update $i, take a look at this:

$i = 10
echo $i + 5 // prints 15
echo $i // prints 10
$i = $i + 5
echo $i // print 15

#8

Thanks Stetim94!

It's clearly far too early on Monday morning to try and learn this stuff.