What is the process of the for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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