0
What is difference between the two js in for loop j= i+1 and j=1
When we have nested for loops and we have var i=0 and var j=1 or var j=i+1.what is the difference between the two js.since i=0 and 0+1=1 .Does that not mean j=1 in both cases?
4 odpowiedzi
+ 1
When the outer loop executes for the first time 'j = 1' for first iteration of inner loop but, on the second execution of outer loop 'i' value will change which will result change in value of 'j'
+ 1
If <i> was the outer loop counter and <j> was the inner loop counter, then j = i + 1 means value of <j> will vary depending on value of <i>.
Whereas j = 1 means <j> value doesn't depend on other variable's value. <j> gets an independent value (integer literal), and if such assignment is placed in a loop, then variable <j> will always get the same value assigned in each loop iteration.
+ 1
Ipang nice answer
0
Snehil Pandey you didn't understand me properly.Thanks all the same