Learn how to use Nested while loop in C Programming language ?

 nested while loop in c

In this article we will talk about nested while loop or nested while statement of C in which following topic are included such as

  • Nested while loop in C
  • Syntax of nested while loop in C
  • Example of nested while loop in C

Nested while loop in C

A nested while loop in C is nothing but, When one or more while loop are declared within block of another while loop such condition is called nested while loop in C.

The first while loop in nested loop is treated as outer while loop in another hand other while loops which are declared within the block of another loop is treated as inner while loop.

Syntax of nested while loop in C

The general form of nested while loop in C are as follows

while(condition)
{
   while(condition)
     { 
        block of statement;
     }
}

Example of nested while loop


#include<stdio.h>
int main()
{
int num,n,cube,d,sum;
printf ("Armstrong numbers are :\n");
num=100;
while(num<=999)     //outer loop
{
n=num;
sum=0;
while(n>0)         /*inner loop*/
{
d=n%10;
n/=10;
cube=d*d*d;
sum=sum+cube;

                /*End of while loop*/
if(num==sum)
printf("%d\n",num);
num++;
}               /*End of outer loop */
return 0;
}

_____________________________________________________________

nested while loop example in c

_____________________________________________________________

Conclusion:

In this article we have learned about nested while loop in C in detail with example, i hope after reading this article you have no any doubt remaining in this topic , but if you have any queries then please ask in comment section.

Post a Comment (0)
Previous Post Next Post