0

Output is different due to i++ position but why ?

var i = 8; while ( i <= 19){ document.write(i + "</br>") i++; } /* output: 8 9 10 11 12 13 14 15 16 17 18 19 */ var i = 8; while ( i <= 19){ i++; document.write(i + "</br>") } /* output: 9 10 11 12 13 14 15 16 17 18 19 20 */ https://code.sololearn.com/W2HJ2Vf4K5rz/?ref=app

2nd Aug 2021, 6:32 AM
Coder
Coder - avatar
3 Réponses
+ 6
In first loop you print <i> value then you increment <i> value. In second loop you increment <i> value, then you print <i> value.
2nd Aug 2021, 7:00 AM
Ipang
+ 4
Coder In the first condition After the document.write i is incrementing that's why it starts printing 8 to till 19 In the second condition After the while condition i is incrementing that's why it starts with 9 ends with 20
2nd Aug 2021, 7:03 AM
R🍁🇮🇳
R🍁🇮🇳 - avatar
2nd Aug 2021, 7:01 AM
Coder
Coder - avatar