Updating 'i' in for loop bug

A Listing of Confirmed Scripting Bugs and Anomalies - Open to all but only moderators can post

Moderators: Tom, Kukurykus

Andrew

Updating 'i' in for loop bug

Post by Andrew »

The more common first form of the for loop in the example below does not update of the 'i' value as expected, the second form works fine. This applies to PS CS, I have not tested it in CS2.

Code: Select all// incorrectly returns 1,2,3
for (var i = 0; i<3; i++) {
   i = i+1;
   alert(i);
}

// returns 1,3 as expected
for (var i = 0; i<3; i=i+1) {
   i = i+1;
   alert(i);
}