Can anybody clarified the used of an inner loop (in any programming language)?
A nested loop is a logical structure used in computer programming where two repeating statements are placed in a "nested" form, i.e., one loop is situated within the body of the other. In a nested loop, the first iteration of the outer loop causes the inner loop to execute. The inner loop then repeats for as many times as is specified. When the inner loop completes, the outer loop is executed for its second iteration, triggering the inner loop again, and so on until the requirements for the outer loop are complete.
for example outer loop goes through rows in 2D array (=rows of table) and inner loop goes through every index in each row (=cells in each rows)
In any language and for any loop, the outer loop will run n times for \[1\le i \le n\]and the inner loop will execute \[\sum_{i}^{n} = n(n-1)/2\] times. A loop is nothing more than the union of a family of mutally disjoint sets. I hope this is the answer that you are looking for.
It's like going round a race track, but on each lap of the main track, you have to turn onto another track and go round that a bunch of times. If you had to go round each of the tracks three times. You'd end up going round the main track three times and the inside track nine time, three times for each of the three laps round the main track. You can, in theory, nest as many loops inside one another as you like. Hope that helps.
Join our real-time social learning platform and learn together with your friends!