JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

C++ : For Loop ( Advance Concept ) in hindi , learn about for loop in c++ language in advanced level

learn about for loop in c++ language in advanced level , C++ : For Loop ( Advance Concept ) in hindi  :-
इससे पहले के article मे , for loop के basic structure को discuss किया है जिसमे for loop मे तीन भाग होते है |
1. initial : इसमें for loop के control variable को initial किया जाता है |
2. Condition : इसमें for loop के control करने के condition को check किया जाता है | जब ये condition true होती है तब तक loop की body execute होगी |
3. Increment / Decrements : इसमें for loop के लिए control variable को  Increment / Decrements किया जाता है |
4.For looping body :इसमें for loop मे perform करने के लिए task को perform करने के लिए किया जाता है |
इस article मे , for loop मे advance concept को discuss किया जाता है |
Changing step size
अभी तक हमने देखा है की for loop मे increment / decreements के लिए step size ‘1’ होती है लेकिन ये जरुरी नहीं है की step size ‘1’ हो | अतः प्रोग्राम के requirement के अनुसार step size को change किया जा सकता है |इसके लिए निन्म statement को consider किया जाता है |
int i = i+2;
यहा पर
i : control variable है |
2 : step size है |
उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
void main()
{
int i;
cout<<“Even number Under 20 :”<,endl;
for(i=0;i<=20;i=i+2)
{
cout<<i<,endl;
}
getch();
}
इस उदाहरण मे even number को display किया जाता है | दो even number मे ‘2’ का अंतर होता है इसलिए इसमें for loop मे step size ‘2’ के साथ even number को display किया जाता है |
इसका आउटपुट होगा :
Even number Under 20 :
2 4 6 8 10 12 14 16 18 20
String inside for loop
for loop का use string के प्रत्येक character को access और display करने की डायरेक्ट सुविधा देता है | उदाहरण के लिए :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
string name ;
cout<<“Enter String :”<,endl;
cin>>name;
cout<<“Reverse Order”;
for(i=strlen(name);i>0;i–)
{
cout<<name[i];
}
getch();
}
इस उदाहरण मे string को reverse order मे display किया गया है | इसके लिए इस उदाहरन मे string.h header file को include किया गया है | जिससे string के pre define function string और strlen() को use किया जा सकता है |
और for loop मे
initial : control variable को string name के length से initial किया गया है |
condition : ये loop जब तक चलता है तब तक i की value ‘0’ से बड़ी होती है |
increment : इसमें i मे ‘1’ का increment किया जाता है |
इसका आउटपुट होगा :
Enter String : Parth
Reverse Order
htrap
Pre Increment / Decreament
Increment / Decreament को loop मे use करने से पहले भी Increment / Decreament किया जा सकता है | इसे pre Increment / Decreament कहते है | अभी तक सभी loop मे Increment / Decreament को loop के एक बार use करने के बाद Increment / Decreament किया गया है | लेकिन Increment / Decreament को loop के execute होने से पहले भी Increment / Decreament भी possible है |
इसका उदाहरन निन्म है |
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=10;
for(i=0;i<5;++i)
{
a=a+10;
}
cout<<“Value of a :”<<a<<endl;
getch();
}
इस उदाहरण मे Pre-Increment को use किया गया है | जिससे ये loop केवल 4 बार ही execute होगा |
क्योकि जब loop पहली बार execute होगा तब i की value ‘1’ होगी | और ये loop तब तक चलता रहेगा जब तक i की value ‘5’ से कम होती है | अतः a की value 4 नहीं हो जाती है |
इसका आउटपुट होगा ;
Value of a : 50
Expression as Increment / Decrements
किसी for loop के Increment / Decrements मे , control variable की value को किसी expression के आउटपुट से Increment / Decrements कर सकते है | इस expression का आउटपुट integer value होनी चाहिए |
इसके लिए उदाहरन होगा :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=10;
for(i=1;i<10;i=i+(2*i))
{
a=a+10;
}
cout<<“Value of a :”<<a<<endl;
getch();
}
इस उदाहरन मे ,i+(2*i) के आउटपुट से control variable ‘i’ की value को update किया जाता है |
जब loop पहले बार चलाया जाता है उसके बाद
i = 3 होगी जो की 10 से कम है | इसलिए addition operation perform होता है | इसके बाद
i=7 होगी जो की 10 से कम है | इसलिए addition operation perform होता है | इसके बाद
i=15 होगी जो की 10 से ज्यादा होती है अतः loop terminate हो जाता है |
इसका आउटपुट होगा
Value of a : 30
Expression as condition
किसी for loop के condition statement मे , control variable की value को किसी expression के आउटपुट से check किया जाता है | इस expression का आउटपुट integer value होनी चाहिए |
इसके लिए उदाहरन होगा :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int a=10;
string name ;
cout<<“Enter Name :”<<endl;
cin>>name;
for(i=1;i<strlen(name);i++)
{
cout<<name[i];
}
cout<<“Value of a :”<<a<<endl;
getch();
}
इस उदाहरन मे string को display किया जाता है | इसके लिए string को यूजर से input किया जाता है |
और loop चलाया जाता है |
condition मे control variable को string के length से check किया जाता है | जो की strlen() function से calculate किया जाता है |
इसका उदाहरन होगा :
Enter Name : Parth
Parth
Value of a : 10
इस article मे , for loop के general format मे हो सकने वाले changes को discuss किया है | अब आगे के article मे while और do-while loop को discuss किया जाता है |
Sbistudy

Recent Posts

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

1 day ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

3 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

5 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

5 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

5 days ago

FOURIER SERIES OF SAWTOOTH WAVE in hindi आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित

आरादंती तरंग की फूरिये श्रेणी क्या है चित्र सहित FOURIER SERIES OF SAWTOOTH WAVE in…

1 week 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