Thursday , November 14 2019

C #10 – Nested Loops in C Language


 

Nested Loops in C Language

C programming allows to use one loop inside another loop. The following section shows a few examples to illustrate the concept.

Syntax

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 );

A final note on loop nesting is that you can put any type of loop inside any other type of loop. For example, a ‘for’ loop can be inside a ‘while’ loop or vice versa.

About Faheem

Faheem
An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

C #07 – Operators in C Language

Operators in C Language An operator is a symbol that tells the compiler to perform …

Leave a Reply

Your email address will not be published.