+ 3

Can someone ,please help better explain this code to me in JavaScript

var i,j; var c=0; for(i=1; i<=3; i++){ for(j=1,j<=2; j++){ c+=j; } } alert(c) output //9 how ,can someone help out here ,to better explain this loop

9th Aug 2018, 10:07 PM
George S Mulbah II
George S Mulbah II - avatar
3 Respuestas
+ 1
The inner loop adds 3 to c: c+= 1 // c === 1 c+= 2 // c === 3 The outer loop repeats the inner loop 3 times, hence 3 * 3 = 9.
9th Aug 2018, 11:30 PM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 2
thank a lot Nguyen Van Hoang
10th Aug 2018, 12:06 AM
George S Mulbah II
George S Mulbah II - avatar
0
You're welcome. Glad to help.
10th Aug 2018, 12:07 AM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar