Skip to content
doubtly

2 answers

Answer: a nested loop is a loop placed inside the body of another loop. For every single iteration of the outer loop, the inner loop runs completely.

for (i = 1; i <= 3; i++)          /* outer loop */
{
    for (j = 1; j <= 4; j++)      /* inner loop */
        printf("* ");
    printf("\n");
}

Output:

* * * *
* * * *
* * * *

The outer loop runs 3 times; each time, the inner loop runs 4 times, so printf("* ") executes \(3\times4 = 12\) times. Any loop (for, while, do-while) can be nested inside any other. Nested loops are used for patterns, tables, and working with 2-D arrays (matrices), where the outer loop handles rows and the inner loop handles columns.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.