While loop in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




This loop is exactly the reverse of the do…while loop. It checks for the condition at the beginning and later executes the given set of statements. Hence there might not be at leastone chance that the statements ate executed.

Syntax:

While(condition)

{

statements;

.

.

}

Example program:

//To display even values between 1 and 10

#include<iostream.h>
#include<conio.h>

void main()

{

int i=2;

while(i<=10)

{

cout<<i<<endl;

i+=2;

}

getch();

}

Output:

2

4

6

8

10

 




Not Satisfied ? Just search & get the result

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

Related posts:

  1. Do…while loop in C++
  2. Nested if statements in C++
  3. if……else statements in C++
  4. Nested If …Else Statements in C++
  5. Simple IF statement in C++

Leave a Comment

Previous post:

Next post: