","answerCount":1,"upvoteCount":1,"suggestedAnswer":[{"@type":"Answer","text":"Understand it step-by-step :\n\nWhen i=0, gets in the loop\ni+=i means i+=0 - > i=0\nprints 0\ni++ - > i=1\ni++ again from the increment of the for loop, i=2, gets in the loop\ni+=2 - > i=4\nprints 4\ni++ - > i=5\nAgain i++ from the increment statement in for loop, i=6\nNow i>=5 hence loop will break.","upvoteCount":2}]} }
+ 1

What is the process of the for loop?

<script> for (i=0;i<5;i++){ i+=i; document.write(i); i++; } </script>

5th Apr 2019, 12:51 PM
KHUSHbu
KHUSHbu - avatar
1 Answer
+ 2
Understand it step-by-step : When i=0, gets in the loop i+=i means i+=0 - > i=0 prints 0 i++ - > i=1 i++ again from the increment of the for loop, i=2, gets in the loop i+=2 - > i=4 prints 4 i++ - > i=5 Again i++ from the increment statement in for loop, i=6 Now i>=5 hence loop will break.
5th Apr 2019, 4:00 PM
Шащи Ранжан
Шащи Ранжан - avatar