Looping in c language in hindi , loops , while , do – while loop , for looping लूप c भाषा में

लूप c भाषा में Looping in c language in hindi , loops , while , do – while loop , for looping :-
इससे पहले goto statement से किसी प्रोग्राम segment को बार बार repeat कर सकते है |लेकिन इसका structure बहुत complex होने पर प्रोग्रम्म की complexity मो बढ़ा देता है |C LANGUAGE मे ,goto statement  के अलावा ,LOOPING की सुविधा भी देता है | LOOPING दो तरह की होती है :-
1.ENTRY CONTROL LOOP:
इस प्रकार मे, control statement looping के शुरुवात मे होती है |अगर condition true नहीं होती है तब LOOP का block execute नहीं होता है |
2.EXIT CONTROL LOOP:
इस प्रकार मे, control statement execute block के बाद होता है | अगर condition true नहीं होती है तब LOOP का block execute एक बार होता है |
किसी भी looping मे control statement बहुत carefully बनाना चाहिए |क्योकि loop का control पूरी तरह condition पर निर्भर करता है |loop मे ,चार प्रकार के operations होते है :-
1.Control variable को set करना |
2.Loop statement को execute करना |
3.Condition को टेस्ट करना |
4.Condition variable को increment करना है |
C language मे तीन looping होती है :-

1. while loop:

While loop entry controlled loop है |इसमें test condition loop के start मे होती है |अगर ये test condition true होती है तब block execute होता है फिर control variable मे increment होता है और condition फिर check होती है |
अगर condition false हो जाती है तब loop block execute नहीं होता है |
इसका syntax है :-
while(condition)
{

 

 block statement ;

 

 control variable increment;
}
उदहारण :
#include<conio.h>
#include<stdio.h>
void main ()
{

 

int a,mul;

 

int i =1;
printf(“Enter your digit”);
scanf(“%d”,&a);
whille (i<=10)
{

 

  mul=a*i;

 

  printf(“%d”,mul);
  i++;
}
}
इस उदहारण मे , प्रोग्रामर table print हो रहा है | जब तक i की value 10 नहीं हो जाएगी तब तक block statement execute होगा |
आउटपुट होगा :
Enter your digit 2
2 4 6 8 10 12 14 16 18 20

2. do – while loop:

ये loop exit control loop है |इसमें execute body condition check होने से पहले execute होती है |इसका मतलब है loop body एक बार तो execute तो होगी |इसका syntax है :-
do
{
statements;
control variable increment;
}
while(condition);
 
इसमें body execute होने के बाद , control variable में increment होता है |फिर condition check होती है |अगर condition true होती है तब loop body फिर से execute होती है |
उदाहरण के लिए :
#include<conio.h>
#include<stdio.h>
void main ()
{

 

int a,mul;

 

int i =1;
printf(“Enter your digit”);
scanf(“%d”,&a);
do
{

 

  mul=a*i;

 

  printf(“%d”,mul);
  i++;
}
whille (i<=10);
}
इस उदाहर मे भी table print होगा लेकिन इसमें एक बार printf statement execute हो जायेगे |बाद initialing और condition check होगा |
आउटपुट होगा :
Enter your digit 3
3 6 9 12 15 18 21 24 27 30
 
उदहारण -2:
#include<conio.h>
#include<stdio.h>
void main ()
{
int sum,a,b ;
sum=3;
printf(“Enter your digit”);
scanf(“%d %d”,&a,&b);
do
{
sum=a+b;
printf(“Your Sum = %d”,sum);
a=a+1;
b=b+2;
}
while((sum/2)==0);
}
 
इस प्रोग्राम मे sum की value 3 है ,फिर भी a और b का addition एक बार perform होगा |फिर sum/2==0 check होगा |और condition सही होने पर , block execute होगा |
आउटपुट होगा :
Enter your digit 22 12
Your Sum = 34
Your Sum = 37
अब condition true नहीं होने पर , loop block execute नहीं होगा |

3. for looping:

for loop entry controlled loop है | while और do-while loop का syntax complex होता है लेकिन for loop के syntax सरल और आसानी से समजा सकता है|इसका syntax है :-\
for(initial ; condition ;  increment )
{
 statements;
}
initial : control variable को initial  करना |
condition : इसमें control expression को check करना |
increment : इसमें control variable का increment करना |
उदहारण के लिए :
 
#include<conio.h>
#include<stdio.h>
void main ()
{

 

int a,mul,i;

 

printf(“Enter your digit”);
scanf(“%d”,&a);
for(i=1;i<=10;i++)
{
 mul=a*i;
 printf(“%d”,mul);
}
}
इस उदहारण मे भी , table print हो रहा है | जब तक i की value 10 नहीं हो जाएगी तब तक block statement execute होगा |
आउटपुट होगा :
Enter your digit 2
2 4 6 8 10 12 14 16 18 20