C++ While Loop

The while is an entry control loop statement. The test condition is evaluated, if the condition is true, then the body of loop is executed. After execution of the body the test condition is once again evaluated and if it is true, the body is executed once again. This process of repeated execution of the body continues until the test condition finally becomes false and the control is transferred out of the loop. On exit, the program continues with the statement immediately after the loop.

Syntax of C While Loop:-

while(test condition)

{

body of the loop

}

Example of While Loop in C++ 

#include<conio.h>
#include<iostream.h>
void main()
{
int a=10;
clrscr();
while(a>0)
{
cout<<a<<endl;
a–;
}
getch();
}

Result :-

while loop in C++

Example of while Loop in C++

  write a program to find the factorial of a value using while loop.

    Write a program to find even no. between 1 to 20 .

  Write a program to print the sum of a natural no.

   Write a program to print the sum of all digits of a no. 

  Write a program to print the number in reverse order.




Follow Us

Contact Us

tutorialworldin@yahoo.com

Back to Top