Nested Loop in C language by R4R Team

What is Nested Loop:

-Loop inside loop is called as Nested loop.

Syntax-
loop
{
loop
{
}
}

Why we need nested loop ?

-To performing some task on multiple dimensional data, we need to excess all dimension of the data so that we use the nested loop.


program-

#include< stdio.h>
int main()
{
int i,j,count=0;
for(i=0;i< 2;i++)
{
for(j=0;j< 5;j++)
{
printf("Inside Loop\n");
count++;
}
}
printf("Total %d times loop run",count);
}


output-

Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Inside loop
Total 10 times loop run

-In this program, we make a nested for loop
-first loop is run 2 times and second loop run 5 times
-so that total runing of loop is 5*2=10




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!