आपकी ऑफलाइन सहायता

BACK
49

सी प्रोग्रामिंग

149

पाइथन प्रोग्रामिंग

49

सी प्लस प्लस

99

जावा प्रोग्रामिंग

149

जावास्क्रिप्ट

49

एंगुलर जे.एस.

69

पी.एच.पी.
माय एस.क्यू.एल.

99

एस.क्यू.एल.

Free

एच.टी.एम.एल.

99

सी.एस.एस.

149

आर प्रोग्रामिंग

39

जे.एस.पी.





डाउनलोड पी.डी.एफ. ई-बुक्स
C - Loop
  • जब तक किसी condition का satisfaction नहीं होता तब तक Loop का statement repeat होता रहता है |

C Loops के 4 प्रकार है |

  1. while loop
  2. do-while loop
  3. for loop
  4. nested loop

1.While Loop

  • While Loop में variable को initialize करना जरुरी है
  • अगर While Loop को repeat करना हो तो, increment/decrement operator का इस्तेमाल किया जाता है
  • जबतक While Loop में Condition true होती तब तक repeat होता रहता है |

Syntax for While Loop

variable initialization ;
while(condition){
  statements;
  variable increment/decrement;
}


for eg.
  while(i<10)
  {
     printf("%d\n",i); // statement of while loop
     i++; //increment operator
  }

Example for While Loop

Source Code :
#include <stdio.h>

int main(){
	
  int i=0; // Variable initialization

  while(i<10) // condition of while loop
  {
     printf("%d\n",i); // statement of while loop
     i++; //increment operator
  }
return 0;
}
Output :
0
1
2
3
4
5
6
7
8
9

2.Do-While Loop

  • जबतक Do-While Loop में Condition true होती तब तक repeat होता रहता है |
  • Do-While की खासियत ये है कि, अगर condition false भी हो तो ये एक statement को output में print करता है |

Syntax for Do-While Loop

do{
  statements;
}while(condition);


for eg.
  do
  {
     printf("%d\n",i);
     i++; 
  }while(i<10);

}

Example for Do-While Loop

Source Code :
#include <stdio.h>

int main()
{
  int i=0; // Variable initialization

  do
  {
     printf("%d\n",i);
     i++;
  }while(i<10);
  
return 0;
}
Output :
0
1
2
3
4
5
6
7
8
9

3.For Loop

  • For Loop को सिर्फ Variable Declaration कि जरुरत होती है | ये statement छोड़के सभी काम अपने अंदर ही करता है |
  • जबतक While Loop में Condition true होती तब तक repeat होता रहता है |

Syntax for For Loop

for( variable_initialization; condition; increment/decrement){
  statements;
}


for eg.
    for( i=0; i<10; i++){
     printf("%d\n",i); // statement of while loop
  }

Example for For Loop

Source Code :
#include <stdio.h>

int main(){
    int i;

    for( i=0; i<10; i++){
     printf("%d\n",i); // statement of while loop
  }
return 0;
}

Output :
0
1
2
3
4
5
6
7
8
9

4.Nested Loop

  • Nested Loop ये loop का कोई प्रकार नहीं है |
  • Nested Loop में एक loop में दूसरा loop लिया जाता है |
  • Nested Loop While, Do-While, For Loop के होते है |

Example for Nested Loop

Source Code :
#include <stdio.h>

int main(){
int i,j;

for(i=1;i<4;i++){

    for(j=1;j<4;j++){

    printf("%d 	%d\n",i,j);
}
}
return 0;
}
Output :
1       1
1       2
1       3
2       1
2       2
2       3
3       1
3       2
3       3