+ 5

I don't understand result this challenge is 3, help me please!

var i = 0, j = 0, count = 0; for (; i < 3; i++) { for(; j < 3; j++) { count++ } } alert(count);

19th Sep 2017, 10:55 AM
Trưởng Nguyễn
Trưởng Nguyễn - avatar
4 Respostas
+ 9
The increment only apply for the case:- ✅ i = 0, j = 0 ✅ i = 0, j = 1 ✅ i = 0, j = 2 only as there's no re-initialization in the inner loop and hence the answer is 3. Tricky! 😉
19th Sep 2017, 11:46 AM
Zephyr Koo
Zephyr Koo - avatar
+ 6
Well there's as a loop always comprises of 3 components:- ✅ Initialization ✅ Condition ✅ Update The usual initialization was moved up to the top in this case.
20th Sep 2017, 1:46 PM
Zephyr Koo
Zephyr Koo - avatar
0
9
20th Sep 2017, 5:13 AM
brijesh
brijesh - avatar
0
Why no re-initialization in the inner loop? I still don't understand, on SoloLearn doesn't teach.
20th Sep 2017, 9:28 AM
Trưởng Nguyễn
Trưởng Nguyễn - avatar