+ 1

Can anyone explain it please? And give an answer.

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

12th Jul 2017, 12:34 PM
Omniscient
Omniscient - avatar
5 Antworten
+ 18
Infinite loop... ~_~
12th Jul 2017, 12:38 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Are you sure of the code? Because actually the nested loop (the one with 'j' counter) is an infinite one, as j is incremented so will never be less or equal to zero, and alert() will never be executed ^^
12th Jul 2017, 12:41 PM
visph
visph - avatar
+ 4
By the way, i assume you meant to write "j--" in the for loop, or else you enter an infinite loop
12th Jul 2017, 12:44 PM
Tzahi Leh
Tzahi Leh - avatar
+ 1
10 The ++ before the variable first adds 1 to it, then use it for your purpose.. You nested 2 for loops, every each runs 3 times => 9 increments to the variable 'count'. Finally, you alert ++count, which means you first add 1 to it and only then alert it, so practically you alert 10
12th Jul 2017, 12:42 PM
Tzahi Leh
Tzahi Leh - avatar
+ 1
Sorry friends.. I have corrected the question now... You were right @tzahi leh... I meant j--
12th Jul 2017, 12:55 PM
Omniscient
Omniscient - avatar