I know how to do simple loops but I don't know what's going on when many loops are working together.For example:for (var i=0; i <= 9; i++){     document.write(i);  for (var m=0; m <= 9; m++){     document.write(i);    }}Is there a way I can learn loops inside out?
How to improve my loop logic in programming?
javascript;programming logic;loops
It's pretty simple actually...you have to think step by step.You enter your first loop with i = 0. The condition is clear, it will not stop to execute what's inside {} while i is inferior or equals 9.Let's see what comes next... you call document.write(). I guess you know exactly what it does.Then... HUHO! ANOTHER LOOP! chill out, it's exactly the same thing.You start your second loop with m = 0 and won't stop while m is inferior or equals 9.Then you write what's inside i using document.write()You're at the end of your second loop context so you re-evaluate what's inside m. m is now equals to m+1 (due to the m++). m equals 1 and as 1 is inferior or equal to 9 it will loop again (it will then write again what's inside i, then add 1 to m). Now m is equals to m+1 (2)... etc. etc.When m will equal 10 then m will not be inferior or equal to 9 anymore so you will stop looping in your second loop, and continue your first loop execution.So now i is equals to 1 (due to i++), i is inferior or equal to 9 so you will execute your first loop again. Inside your first loop there is the document.write() call but there is the second loop.You enter your second loop with m set to 0... and it goes on and on...But as you always write what's inside of i, you will have ten 0 displayed, then a linebreak then ten 1 displayed, then a linebreak... and so on until 10.