Friday, July 29, 2016

C Basics - Nested Loop in C

The way if statements can be nested, similarly while and for can also be nested. Not only this, a for loop can occur within a while loop, or a while within a for.

The syntax for a nested for loop statement is,

for ( init; condition; increment ) {

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

The syntax for a nested while loop statement is,

while(condition) {

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

The syntax for a nested do...while loop statement is,

do {

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

}while( condition );



Related topics:
Loops in C   |   The for Loop in C   |   The while Loop in C   |   The do-while Loop in C   |   Infinite Loop in C   |   Loop Control Statements in C   |   The break Statement in C   |   The continue Statement in C   |   The goto Statement in C   |   The return Statement in C

List of topics: C Programming

No comments:

Post a Comment