Loops in c++ programming
![]() |
Loop |
Loop
A close patt is called loop.
There are three type of loop:-
There are three type of loop:-
- For loop.
- While loop.
- Do while loop.
1.For loop
To run the body continuously until a required condition is fullfill is called looping. It is used to perform looping Operation. When the condition will become false the execution for loop will be stopped.
Syntax
![]() |
For loop Syntax |
Example
#include<stdio.h>
int main()
{
for(int i=1;i<=10;i++)
{
cout<<i<<"\n";
}
}
### Output ###
1
2
3
4
5
6
7
8
9
10
2.While loop
To run the body continuously until a required condition is fullfill is called looping. It is used to perform looping Operation. When the condition will become false the execution for loop will be stopped.
![]() |
While loop syntax |
#include<iostream.h>
int main()
{
int i=1;
while(i<=10)
{
cout<<i<<"\n";
i++;
}
}
### Output ###
1
2
3
4
5
6
7
8
9
10
3. Do while loop
To run the body continuously until a required condition is fullfill is called looping. It is used to perform looping Operation. When the condition will become false the execution for loop will be stopped.
#include<iostream.h>
int main()
{
int i=1;
do
{
cout<<i<<"\n";
i++;
}
while(i<=10);
}
### Output ###
1
2
3
4
5
6
7
8
9
10
Comments
Post a Comment
If you have any doubt. Please comment me know.