for, while, do-while

Nested Loop in C | Nested Loops in C : for, while, do-while

C

Nested Loop in C :- Loop Ke Under ek or loop hona hi nested loop kahlata hai.C Programming me nested loop ka bahut istemal hota hai.

for, while, do-while
Nested Loop in C

Nested loop in Hindi me samanjh ne ke liye ham syntax or program example niche dekh te hai.

Nested Loops in C – for, while, do-while with Example

Contents

Types Of Nested Loop In C

  • Nested While loop
  • Nested Do-While loop
  • Nested For loop

Nested While loop

Syntax :-

while (condition1)
{
    statement(s);
    while (condition2)
    {
        statement(s);
        ...........
    }
    ............
}

Example :-

#include <stdio.h>
#include <conio.h>
int main()
{
    int i=1,j;
    clrscr();
    while (i <= 5)
    {
        j=1;
        while (j <= i )
        {
            printf("%d ",j);
            j++;
        }
        printf("\n");
        i++;
    }
    return 0;
}

Output :-

1
1 2
1 2 3 
1 2 3 4
1 2 3 4 5

Nested Do-While loop

Syntax Nested Do-While

do
{
    statement(s);
    do
    {
        statement(s);
        ............
    }while (condition2);
    .........
}while (condition1);

Example :-

#include <stdio.h>
#include <conio.h>
int main()
{
    int i=1,j;
    clrscr();
    do
    {
        j=1;
        do
        {
            printf("*");
            j++;
        }while(j <= i);
        i++;
        printf("\n");
    }while(i <= 5);
    return 0;
}

Output :-

*
**
***
****
*****

Nested For loop

Syntax Nested For Loop

for ( init; condition; increment ) 
    {

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

Example :-

#include <stdio.h>
 
int main () {

   /* local variable definition */
   int i, j;
   
   for(i = 2; i<50; i++) {

      for(j = 2; j <= (i/j); j++) 
      if(!(i%j)) 
        break;      // if factor found, not prime
      if(j > (i/j))
       printf("%d is prime\n", i);
   }
 
   return 0;
}

Output :-

2 is prime
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
37 is prime
41 is prime
43 is prime
47 is prime

Nested Loop in C

Dosto mujhe ummed hai ki aap Nested Loops in C hindi ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre or ha agar aap video bhi dekhna chahte hai to aap mere channel ko bhi subscribe kar sakte hai. channel ka link aapko home page par mil jayega |

1 thought on “Nested Loop in C | Nested Loops in C : for, while, do-while

Leave a Reply

Your email address will not be published. Required fields are marked *