Nested for loop

Estudies4you
Nested for loop
When a ‘for loop’ is enclosed in another for loop, the structure is called a nested for loop. In nested loop the inner loop is executed first and then the outer loop executed.
Syntax:
for(expression1; condition1; expression2)
{
body-of-loop 1
for(expression3; condition2; expression4)
{
body-of-loop 2
}
}

Example:
Program: Simple program to print numbers on a line
#include<stdio.h>
int  main(void)
{
//statements
for(int i=1; i<=3; i++)
{
printf(“Row %d:”,i);
for(int j=1; j<=5; j++)
printf(“%3d”,j);
printf(“\n”);
} //end for
Return 0;
} // end main
OUTPUT:
Enter your numbers: <EOF> to stop
15
22
3^d
The total is: 40

To Top