Matej Posted July 27, 2014 Share Posted July 27, 2014 var x=0;for(var i=0;i<10;i++){ if(i%5==0){continue} x++;}alert(x) why does x=8 here? shouldnt be it 9? when i=5 the loop exits(omiting increment) and continues which means when i=5 x=5 also , so x should have end as 9. Link to comment Share on other sites More sharing options...
johncc Posted July 28, 2014 Share Posted July 28, 2014 0%5==0 and 5%5==0, so 2 increments missed. i x 0 0 1 1 2 2 3 3 4 4 5 4 6 5 7 6 8 7 9 8 Link to comment Share on other sites More sharing options...
davej Posted July 28, 2014 Share Posted July 28, 2014 Because i%5==0 is true for i=0 and i=5 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now