I’ve got a for loop like this:
for (var i=first; i<=last; i++)
{
$("#markers").append("<div class='marker'>"+i+"</div>");
}
first is set to 2001 and last is 2010. This works fine. The problem is when I change it to:
for (var i=first; i<=last; i+=1)
{
$("#markers").append("<div class='marker'>"+i+"</div>");
}
(Notice the different final declaration is different). Any variation other than i++ results in an infinite loop. It’s very strange as a jsFiddle with the same parameters works happily. Any suggestions?
I would guess that
firstis set in a way that ambiguously could be interpreted as astring. So the first version can only be interpreted as increment, but the second is being interpreted by javascript as string concatenation.