var x = 0;
var interval = setInterval(function() {
alert("Loop iteration #" + x++);
if(x==6) {
var x = 0;
}
}, 500);
This code prompts "#NaN" with each message, but I expected it to be going 1, 2, 3, 4, 5 and then back to 1, 2, 3, 4, 5. For endless loop.