8 of 11


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/1?curriculum_id=506324b3a7dffd00020bf661


I think I made an infinite loop even though my code looks almost exactly like code that was approved in previous exercises. Does anyone see the error?


var wLoop = true;
        while (wLoop) {
            console.log(wLoop);
    wLoop = false;
}
for (i=0; i< 50; i=5) {
        console.log(i);
}


#2

i will always be equal to 5, so it is infinite.


#3

ok, I changed it from i=5 to i++ and the same thing happens, page freezes


#4

@biff75 Looks like you've accidentally declared a global variable. Try refreshing and then declaring the var deliberately with the variable keyword and see if that helps.


#5

Please post your code.

@msfrisby, A global variable won't effect it here. :slight_smile:


#6

@cadecodes Yes, I agree with you there :slight_smile: But I thought there was a tiny chance it's holding onto the old value for some reason (er, or maybe that is what you were referring to :smile:); plus, it's good to enforce the practice of using var, no? :nerd:


#7

I don't like using var in loops. I think it takes too much time! :wink:


#8

:joy: So. True. The time I waste on var could be much better spent adding more +'s to my incrementor!


#9

It's just printing it to many times...
Try something like i+=5 to make it print less.


#10

var wLoop = true;
while (wLoop) {
console.log(wLoop);
wLoop = false;
}
for (i=0; i< 50; i+=5) {
console.log(i);
}

that's the code that finally ran on jsbin, it allows me to save and submit easily, thanks for all the help so far @cadecodes @msfrisby @cssblaster41135