How does increments work in loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How does increments work in loops

for (let n=2; n<10; n++){ console.log(n); gives a count 2 to 9 while console.log(n++) give values 2,4,6,8 only...why is that? why is 3,5,7 excluded ... }

15th Dec 2017, 5:03 AM
Louis McIntosh
Louis McIntosh - avatar
1 Answer
+ 1
when you do .log(n++) you not only print but increment n so after first iteration n will be 3 then for will increase it, next .log(n++) will print and increase again
15th Dec 2017, 5:22 AM
Dima Makieiev
Dima Makieiev - avatar