Nested loops in C Language
0 877
A Nested Loop in C works like a set of instructions within a set of instructions.
The outer loop determines how many rows there are, while the inner loop decides how many columns are in each row.
Each loop has a role, helping you organize and handle tasks efficiently.
You can choose any loop type, such as a while loop, for loop, and others to achieve your goal.
Nested loop in C
The syntax of Nested for loop in C language
for(initialization; condition; increment/decrement)
// outer loop code
{
for(initialization; condition; increment/decrement){
//inner loop code
}
}
In each iteration of the outer loop, you can execute any valid C code multiple times within the inner loops, customizing actions for each row and column.
Example:
#include <stdio.h>
int main()
{
// Outer loop
for(int m = 1 ; m <= 2; m++)
{
// Inner loop
for(int n = 1; n <= 2; n++)
{
printf("(%d, %d) ", n, m );
}
printf("\n");
}
return 0;
}
Output:
(1, 1) (2, 1) (1, 2) (2, 2)
Share:



Comments
Waiting for your comments