+ 3
Tricky JS Loops
I'm having difficulty understanding the logic behind the answer in the following loops. Can someone explain in details, what is going here? Thank you, in advance! https://code.sololearn.com/WoEo8N12nCP5/?ref=app
3 Antworten
+ 5
Thank you for your help. I still don't get the 2nd example. I copied the loops from the JavaScript challenges. Those were the answers that were given at the end of the challenges.
+ 3
Both the answer written as a comment is wrong
the value of i for the first for loop will be 6
let see
k= 6;
for(var i =0; i<k; i++){
k+=0 //it means k= k+0;
}
As you can see for
i=0 k=6+0=6
i=1 k=6+0=6
..
similarly when
i=5 k= 6+0= 6
Now I will increase by 1 it means now i=6as it is going on
then it will check the condition
i<k that is 6<6 which is wrong hence for loop stops executing
and we will get the value of i as 6
same method for the 2nd for loop you can apply
If you get this..do comment
+ 3
Just try to solve the second for loop on pen and paper as above
follow the flow of the loop definitely you will get it