The while statement examines or evaluates a condition. The syntax of the while statement is:
while(Condition) Statement;
To execute this expression, the compiler first examines the Condition. If the Condition is true, then it executes the Statement. After executing the Statement, the Condition is checked again. AS LONG AS the Condition is true, it will keep executing the Statement. When or once the Condition becomes false, it exits the loop.
Here is an example:
int Number;
while( Number <= 12 )
{
cout << "Number " << Number << endl;
Number++;
}
|
|
To effectively execute a while condition, you should make sure you provide a mechanism for the compiler to use a get a reference value for the condition, variable, or expression being checked. This is sometimes in the form of a variable being initialized although it could be some other expression. Such a while condition could be illustrated as follows:
| #include <iostream>
void main()
{
int Number;// = 0;
while( Number <= 12 )
{
cout << "Number " << Number << endl;
Number++;
}
getch();
}
|
|
|
0 comments:
Post a Comment