Friday, 23 August 2013

Javascript continue statement in while loop causes an infinite loop

Javascript continue statement in while loop causes an infinite loop

I'm trying to create a while loop with a continue statement. However it
seems to be causing an infinite loop and I can't figure out why.
The code below to me seems like it should start with the var tasksToDo at
3 then decrement down to 0 skipping number 2 on the way.
Any help with what Im doing wrong here greatly appreciated.
var tasksToDo = 3
while (tasksToDo > 0) {
if (tasksToDo == 2) {
continue;
}
console.log('there are ' + tasksToDo + ' tasks');
tasksToDo--;
}

No comments:

Post a Comment