while loop control

While loop checks whether the written condition is true or false.If the condition is found true, then statements written in the body of the while loop i.e., inside the braces { } are executed. Then, again the condition is checked, and if found true then statements in the body of the while loop are executed again. This process continues until the condition becomes false.

The syntax of the while loop is as follows:

while(condition)
{
    statement(s);
}    
#include
#include
void main()
{
    int n=1;
    while(n<=10)
    {
        printf("2 * %d = %d\n",n,2*n);
        n++;
    }
    getch();
}

Output

2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
2 * 10 = 20