For Loop
for loop use for counter ……
4 parts in for loop
(1) initialization
(2) condition
(3) increment and decrement
(4)body of loop
Intialzation me ham varible ko value dity hai // a=11 or h=7 or j=9 etc
Condition me u know k contion check karty hai // a<=90 or h>=1 etc
++ ---
{
statement;
}
syantx
for(initialize;condtion;++/--)
{
statement;
statement;
}
syantx
for(initialize;condtion;++/--)
{
statement;
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a;
for(a=1;a<=5;a++)
cout<<a<< endl;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a= 1;
for(;a<=5;)
{
cout<<a<<endl;
a++;
}
getch();
}
ye dono programme same hai ye ap logo ko dikna ta k esa b ho sakta hai ok chaloo ab es ko run kartyu hai kon run kary ga mujy to nahe ata
#include<conio.h>
void main()
{
int a;
for(a=1;a<=5;a++)
cout<<a<< endl;
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int a= 1;
for(;a<=5;)
{
cout<<a<<endl;
a++;
}
getch();
}
ye dono programme same hai ye ap logo ko dikna ta k esa b ho sakta hai ok chaloo ab es ko run kartyu hai kon run kary ga mujy to nahe ata
· Acha es me ham ne int type ka a varible liya
· Per for loop lagi k agr a less hai 5 se ya eqal hai to true hai q k a ke value 1 hai a me increment ho jai ge
· Body me ajy ga 1 print ho jy ga line change ho jai ge q k endl lagi hai
· a me increment ho ge 2 ho jay ga
· loop me check kary ga to liss hai true ho ga
· body me ajy ga 2 print ho jay ga
· a me increment ho jay ga 3 ho jay ga
· loop me jay condition check ho ge true hai q k a 3 hai ur 5 se less hai
· 3 print ho jay ga a me ++ ho jay ga 4 ho jay ga
· Loop me jay ga condtion check ho ge
· Es traha ho jabn condition false ho jay ga to output aye
1
2
3
4
5
Table
#includde<iostream.h>
#include<conio.h>
#include<conio.h>
Void main()
{
int tab,c,r;
cin>>tab;
for(c=1;c<=10;c++)
{
r=tab*c;
cout<<tab<<”*”<<c<<”=”<<r<<endl;
}
getch();
}
{
int tab,c,r;
cin>>tab;
for(c=1;c<=10;c++)
{
r=tab*c;
cout<<tab<<”*”<<c<<”=”<<r<<endl;
}
getch();
}
Ap sab es ka run approch comment me likooo jes tarha me likta hun ok jesa while me and do-while kia ta same wesa he hai par us se na dikoo ok ur sab comment me likoooo tek hai
Note:: es k bad ek ur simple for loop ke practice ho ge than assignement and quiz ho ga ur bht zada tof ho ga ur per us k bad nested loops start hun gy
No comments:
Post a Comment