Why the output can show the result until 6? As we know the conditon of loop can operate it just until var i reach the value of 5 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why the output can show the result until 6? As we know the conditon of loop can operate it just until var i reach the value of 5

https://code.sololearn.com/WqgmC5TjBOtb/?ref=app https://code.sololearn.com/WqgmC5TjBOtb/?ref=app

6th Oct 2017, 4:00 AM
Grujs Farhan Nafis
Grujs Farhan Nafis - avatar
4 Answers
+ 8
Because there's an increment inside the for loop which produce the result 6 and get printed. After the last iteration it get incremented to 7 and the loop exits since it's greater than 5.
6th Oct 2017, 4:05 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
Absolutely!
6th Oct 2017, 7:08 AM
Zephyr Koo
Zephyr Koo - avatar
+ 2
So the result 6 here is the effect of incremented number by the last variable 5 as the final condition of the loop?
6th Oct 2017, 6:27 AM
Grujs Farhan Nafis
Grujs Farhan Nafis - avatar
+ 2
Thanks a lot buddy, Jazakallahukhair
6th Oct 2017, 7:16 AM
Grujs Farhan Nafis
Grujs Farhan Nafis - avatar