Explain to me


var whileCount = 0

while(whileCount != 1) {
console.log("While loop OK")
whileCount = 0

why doesn't my code work, my code always freezes

for(var i = 0; i != 1; i++) {
console.log("For loop OK")

var doCount = 0

do {
console.log("Do loop OK");
} while (doCount);


In that while loop, whileCount is always not equal to 1 (because whileCount=0), so the code never stops running.

You never define an end for this loop.


Your correct about the infinite loop on the first but the second actually works although I guess that it is more luck then intended. 0 used in conditions works as a falsy value so the do while loop will print the message as expected and then stops as the condition is false.


Oh yeah, keeps slipping my mind.