what is nested loop in c

what is nested loop in c

1 year ago 60
Nature

A nested loop in C is a loop statement inside another loop statement. It allows the looping of statements inside another loop, and any number of loops can be defined inside another loop. There is no restriction for defining any number of loops, and the nesting level can be defined at n times. You can define any type of loop inside another loop, such as a while loop inside a for loop. The syntax for a nested for loop statement in C is as follows:

for ( init; condition; increment ) {
   for ( init; condition; increment ) {
      statement(s);
   }
   statement(s);
}

The syntax for a nested while loop statement in C programming language is as follows:

while(condition) {
   while(condition) {
      statement(s);
   }
   statement(s);
}

The syntax for a nested do...while loop statement in C programming language is as follows:

do {
   statement(s);
   do {
      statement(s);
   }while( condition );
}while( condition );

It is possible to put any type of loop inside any other type of loop, and nested loops are useful in many programming situations.

Read Entire Article