2 answers
Best answer
A nested loop is a loop within a loop, an inner loop within the body of an outer one.
Mr C.
· 20 Jun 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
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?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.