10. To learn it you gota do it: infinite loop


#1

I have looked at the other posts in here and am still stuck. why does this give me an infinite loop?

var count = 1;
var getToDaChoppa = function(){
do {
} while (count < 2);
console.log("Have you seen Da Choppa");
count++;
};
getToDaChoppa();


#2

Hi this part

do { 
} while (count < 2);
console.log("Have you seen Da Choppa");
count++;
};

You should put your console.log inside the do{} and also the count++


#3

Thanks I did it and it worked.

Thanks again,

Glenn


#4

Your solution worked for me and I can see why having the count++ inside the do{} makes more sense but why does having count++ after while send it on an infinite loop?


#5

Because then it is outside of the loop and will only be evaluated after you are done with the loop. So when the loop condition is true the count++ is out of range which means it is not changed and stays true and so your trapped in the loop. Because the way to get out can only be reached if you're outside of it already.