Loops in c++ programming

Loop


Loop

A close patt is called loop.

There are three type of loop:-
  1. For loop.
  2. While loop.
  3. 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.


Syntax
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



Example

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.

Syntax
Do while loop

It's body will execute untill the given condition is true.


#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

Popular posts from this blog

Function in C++ with example & declaration, initialization function in c++

Operators of c++

Storage class in c++