JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

C++ : Do-While or While Loop in hindi , what is do while and while loop in c++ language with program example

what is do while and while loop in c++ language with program example , C++ : Do-While or While Loop in hindi :-
इससे पहले के article मे , for loop के बारे मे discuss किया है अब इस article मे while और do-while loop को discuss करते है |
While loop
while loop के syntax मे initial और update statement को नहीं लिखा जाता है | इसमें केवल test condition को लिखा जाता है | इसका syntax होता है :-
while(test condition)
{
body ;
}
इस syntax मे initial को while loop के बहार लिखा जाता है | और update statement को loop की body मे लिखा जाता है |
सबसे test condition को check किया जाता है | अगर test condition true होती है तब  loop की body को execute किया जाता है |
इस loop body मे केवल एक statement होता है तब {} को use करना complusy नहीं होता है | लेकिन एक statement से ज्यादा statements होता है तब {} को use करना चाहिए |
जब इस body execute हो जाती तब loop का control while loop की start मे आ जाता है | फिर से condition check की जाती है | अगर condition true होती है तब loop की body फिर execute हो जाती है |
ये प्रोसेस तब तक चलती है जब तक condition true होती रहती है |
अगर किसी loop को terminate करना होता है तब test condition को इसी तरह से set किया जाता है |
While loop entry level loop है जिसका मतलब है की अगर loop की condition को false होगी तो loop की body एक बार भी execute नहीं होता है |
इसका उदाहरन होता है :
#include<iostream.h>
#include<conio.h>
void main()
{
int mul,number ;
int i = 1;
cout<<“Enter number : “<<endl;
cin>>number;
cout<< “Table of “<<number<<endl;
while(i<=10)
{
mul=number*i;
cout<<number <<“*”<< i <<“=”<< mul<<endl;
i++;
}
getch();
}
इस article मे , while loop से table को print  किया जाता है | इसके लिए :-
सबसे पहले i को 1 से initial किया जाता है | और while loop मे condition i<=10 को check करते है | और loop की body मे i की value को increment किया जाता है | यूजर द्वारा input किया गया value ‘2’ है |
तब i = 1 है तब mul = 2 होगा |
तब i = 2 है तब mul = 4 होगा |
तब i = 3 है तब mul = 6 होगा |
तब i = 4 है तब mul = 8 होगा |
तब i = 5 है तब mul = 10 होगा |
ये loop तब तक चलता है जब तक i की value 10 नहीं हो जाती है |
इसका आउटपुट होगा :-
Enter number : 4
Table of 4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
4*9=36
4*10=40Do-While loop
Do while loop के syntax मे initial और update statement को नहीं लिखा जाता है | और Do while loop के statement को body के बाद लिखा जाता है | इसमें केवल test condition को लिखा जाता है | इसका syntax होता है :-
{
body ;
}
do while(test condition)
इस syntax मे initial को do while loop के बहार लिखा जाता है | और update statement को loop की body मे लिखा जाता है |
सबसे पहले loop की body perform होती है फिर loop की condition check की जाती है |
वwhile loop की तरह , अगर  loop body मे केवल एक statement होता है तब {} को use करना complusy नहीं होता है | लेकिन एक statement से ज्यादा statements होता है तब {} को use करना चाहिए |
जब इस body एक बार perform हो जाती तब loop का condition check की जाती है | condition के true होने पर body को perform किया जाता है | फिर से condition को check किया जाता है | ये प्रोसेस तब तक चलती है जब तक condition true होती रहती है |
अगर किसी loop को terminate करना होता है तब test condition को इसी तरह से set किया जाता है |
Do-While loop ending level loop है जिसका मतलब है की loop की body एक बार तो perform होती है | उसके बाद condition को check की जाती है |
इसका उदाहरन होता है :
#include<iostream.h>
#include<conio.h>
void main()
{
int mul,number ;
int i = 1;
cout<<“Enter number : “<<endl;
cin>>number;
cout<< “Table of “<<number<<endl;
{
mul=number * i;
cout<<number <<“*”<< i <<“=”<< mul<<endl;
i++;
}
do while (i<=10);
getch();
}
इस article मे , do-while loop से table को print  किया जाता है | इसके लिए :-
सबसे पहले i को 1 से initial किया जाता है | और loop की body मे  table की first row को print किया जाता है | उसके बाद i की value को increment किया जाता है | फिर condition check की जाती है | अगर यूजर द्वारा input किया गया value ‘2’ है |
तब i = 1 है तब mul = 2 होगा | इसके बाद i की value increment किया जाता है |
तब i = 2 है तब mul = 4 होगा |इसके बाद i की value increment किया जाता है |
तब i = 3 है तब mul = 6 होगा |इसके बाद i की value increment किया जाता है |
तब i = 4 है तब mul = 8 होगा |इसके बाद i की value increment किया जाता है |
तब i = 5 है तब mul = 10 होगा |इसके बाद i की value increment किया जाता है |
ये loop तब तक चलता है जब तक i की value 10 नहीं हो जाती है |
इसका आउटपुट होगा :-
Enter number : 4
Table of 4
4*1=4
4*2=8
4*3=12
4*4=16
4*5=20
4*6=24
4*7=28
4*8=32
4*9=36
4*10=40इस article मे while और do-while loop को discuss किया है अब आगे के article मे while और do-while loop के उदाहरनो को discuss करेगे |
Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now