0
JS Nested loop
Why var = a ; is printing 1,2,3,4 and 5 times can anyone explain it? https://code.sololearn.com/WXf0BrGoQM1w/?ref=app
9 Antworten
+ 1
FAITH
increment of b depends on a
So if a = 1 then b range will be 1 to 1 so a will print 1 time
For a = 2 , b range will be 1 to 2 so a will print 2 times
For a = 3, b range will be 1 to 3 so a will print 3 times.
For a = 5, b range will be 1 to 5 so a will print 5 times.
+ 1
FAITH
Because you have range from 1 to 5 and you have printed a and inner loop depends on outer loop.
+ 1
FAITH
Now you are printing b. Operation is same only value changed.
+ 1
FAITH
For a = 1, b will print 1
For a = 2, b will print 1 2
For a = 5, b will print 1 2 3 4 5
+ 1
FAITH
Yes a will print 5 times because for a = 5 inner loop will run till 5 times and a will be print 5 times because a is not changing.
+ 1
FAITH
Yes because for a = 5 inner loop runs 5 times so if you print b then it will print 1 2 3 4 5 and if you print a then it will print 5 5 5 5 5
0
🅰🅹 🅐🅝🅐🅝🅣
So is it depend on increment of var b ?
0
🅰🅹 🅐🅝🅐🅝🅣
Check the code Again .can you explain it?
0
🅰🅹 🅐🅝🅐🅝🅣
For a = 5, b range will be 1 to 5 so a will print 5 times.
It is printing like 5 5 5 5 5
But
For a = 5, b will print 1 2 3 4 5
Why it is printing 1 2 3 4 5 ?