while(condition) statement;
or for a block as
while(condition)
{
sequence of statements
}
The condition that controls the loop can be any valid C++ expression.
Example
*/ This portion of a program can be used to ensure that user enters the
correct response*/
#include <iostream.h>
main()
{
char ans; //character assignment
cout <<"Do you want to continue (Y/N)";
cin>> ans;
while((ans !='Y')&&(ans !='N'))
{
cout <<"n You must type a Y or an N n";
cout <<"Do you want to continue (Y/N)";
cin>> ans;
}
return 0;
}
Example
/* This program displays all printable characters,
including the extended character set, if one exists. The
unsigned char modifies and extends the char to go from 0 to 255 */
#include <iostream.h>
main()
{
unsigned char ch;
ch=1;
while(ch !=0){
cout<<ch;
ch++;
}
return 0;
}