0

How to solve this problem?? Say in detail so i can understand..

var x=1; for(i=0; i<=10; i++){ for (j=0; j>=2; j++){ for(k=0; k<5; k++){ x++; } } } document.write(x);

27th Dec 2016, 6:20 PM
Chirag Panchal
Chirag Panchal - avatar
2 Answers
+ 6
k max value is 5, j is 0 and i is 11 their multiplication is 0 so output will be initial x (1) when for loops are nested, calculate their max value and and multiply them
27th Dec 2016, 6:30 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
You have to count how many time each loop will be done. The one with "i" will be done 11 times. The one with j will never be done as 0>=2 is false (11*0). The k one will never be done because of the j one (11*0*5). So the output is 1
27th Dec 2016, 6:26 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar