C Nested Loops

Last Updated Nov 20, 2015, 07:00:14 PM





A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes. Of course, a break within either the inner or outer loop would interrupt this process.

Nested loop can be either for loop, do while loop or while loop. Meaning you can nest two for loops or two while loops. See the below example

Syntax



Example Try It Now

Using nested loops in C? - StackOverFlow



Other Loop Topics you might want to learn

for loop in C

while loop in C

do while loop in C