+ 2

loop in javascript

I want someone to explain this for(i=0;i<10;++i){ i+=2 console.log(i) }

7th Jun 2022, 4:01 PM
Sara Ali
Sara Ali - avatar
4 Answers
+ 3
i = 0 i += 2 =>i=2 prints 2 ++i ; //i=3 3 < 10 true i += 2 // i=5 prints 5 ++i ; //i=6 6 < 10 true i += 2 //i=8 prints 8 ++i ; //i=9 9 < 10 true i += 2 //i=11 prints 11 ++i ; // i=12 12 < 10 false , stops loop Hope it helps..
7th Jun 2022, 4:09 PM
Jayakrishna šŸ‡®šŸ‡³
+ 3
JayakrishnašŸ‡®šŸ‡³ Many thanks I understood
7th Jun 2022, 4:16 PM
Sara Ali
Sara Ali - avatar
0
for(i=0;i<=10;i=i+1){console.log(i)} i=0;while(i<=10){console.log(i);i=i+1}
8th Jun 2022, 9:23 PM
aliz6398suisiTerminatorEmpireBot
aliz6398suisiTerminatorEmpireBot - avatar