Do…while loop in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




A do…while loop is used when the statements are to be executed at the beginning and later the condition to be checked. Hence there is at least one chance that the given statements are executed.

Syntax:

do

{

statements;

.

.

}

while(condition);


Example program

//To print natural numbers from 1 – 10

#include<iostream.h>

#include<conio.h>

void main()

{

int i=1;

do

{

cout<<i<<endl;

i++;

}

while(i<=10);

getch();

}

 

Output:

1

2

3

4

5

6

7

8

9

10

See also: While loop in C++

 

 


 

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. if……else statements in C++
  2. Nested if statements in C++
  3. Nested If …Else Statements in C++
  4. Simple IF statement in C++
  5. C program to find the sum of first 50 natural numbers using for loop

Leave a Comment

Previous post:

Next post: