Javascript, For loop: returned 'i' value is different from that is stored -


in loop alert(i) alerts 12,and firebug displays 10 end result.

 for(var i=0;i<=10;i=i+2){       document.write=i;     }      alert(i); 

i gets incremented after every iteration of loop. when fails condition <= 10 loop breaks:

0 => loop gets executed, incremented 2 2 => loop gets executed, incremented 2 4 => loop gets executed, incremented 2 6 => loop gets executed, incremented 2 8 => loop gets executed, incremented 2 10 => loop gets executed, incremented 2 12 => loop breaks => remains @ 12 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -