+ 14

How is anwser 207

var x = 9; for(var i=0;i<=10;i++) { for(var j=2;j>0;j--) { x+=9; } } console.log(x);

22nd Aug 2018, 2:14 PM
Shubham goyal
Shubham goyal - avatar
11 Respostas
+ 14
var x = 9; { for(i=0;i<=10;i++)// 0,1,2,3,4,5,6,7,8,9,10 = 11 { for( j=2;j>0;j--) /* 0,1 = 2 */ { x+=9; // 11 * 2 * 9 + 9 = 207 } } } console.log(x);
22nd Aug 2018, 2:27 PM
narender
narender - avatar
+ 11
11×2×9 + 9 = 207
22nd Aug 2018, 10:39 PM
ShortCode
+ 8
A variable x is declared with value 9. A for loop is there with initial value as 0. and runs till I is equal to 10 so 11 times. Inside this another loop is there with initial value of 2 and runs till j is greater than 0. There it runs two times. x =+ 9 is increasing x value everytime. The loops will increase the value for 11*2 times , i.e. 22 times. 22*9 is equal to 198. The value of x will be 9+198 = 207.
22nd Aug 2018, 2:26 PM
Akash Pal
Akash Pal - avatar
+ 3
x starts from 9. now, the outer loop executes 11 times, and for each one of them, 2 times +9, so for each outer loop you are doing +18. 11*18 = 198 plus the first 9, 198+9 = 207
22nd Aug 2018, 2:27 PM
Bebida Roja
Bebida Roja - avatar
+ 2
hey man. Note that the second loop is inside of first. The first run 11 time and o second 2 time. But the second run 2*11 becouse is inside of first it, in other word, every 1 time of first the second run 2 time in second. Look: 0 = +9 +9 = 18 1 = +9 +9 = 36 2 = +9 +9 = 54 ... until 10 (11 times) +9 value of x.
23rd Aug 2018, 1:38 AM
Mr Genesis
Mr Genesis - avatar
+ 1
first loop will run 11 times and 2nd will 2 times hence 11*2=22 times but 9 already assigned to x so total 23 ie 9+9+9+ - - -(23 times)=9*23=207
22nd Aug 2018, 5:02 PM
Vimlesh Kumar
Vimlesh Kumar - avatar
+ 1
var x = 9; { for(i=0;i<=10;i++)// 0,1,2,3,4,5,6,7,8,9,10 = 11 { for( j=2;j>0;j--) /* 0,1 = 2 */ { x+=9; // 11 * 2 * 9 + 9 = 207 } } } console.log(x);
23rd Aug 2018, 4:00 PM
Amaram Rushi Vivek
Amaram Rushi Vivek - avatar
0
Wow, this question along with responses have helped me understand multiplication can help me quickly calculate through loops. Thanks!
24th Aug 2018, 2:49 AM
Nathan Hancock
Nathan Hancock - avatar
0
Bebida Roja var x=9; function funcInLoop(){ return 9*2; } for(i=0;i<=10;i++){ x += funcInLoop(); } console.log(x) https://code.sololearn.com/W9Oddm5zeH58
24th Aug 2018, 7:24 PM
Mr Genesis
Mr Genesis - avatar
- 1
https://code.sololearn.com/We2M9ZM86WfQ/?ref=app Don't use loop inside loop. It's best use recursive function, or a function it. The loop get many resources. Look: for (var i=0;i<= 10;i++){ /* put the function here inside. */ funcInLoop(test); /* This function should exist. */ }
24th Aug 2018, 11:18 AM
Mr Genesis
Mr Genesis - avatar
- 1
Mr Genesis de Souza Rosa Genesis what if there is a for loop in funcInLoop?
24th Aug 2018, 2:04 PM
Bebida Roja
Bebida Roja - avatar