Looping

Let's say that we would like the processor to do something until certain condition are met. For example to print value in variable a until value in variable a is 100.This is easily accomplished with a for loop or a while loop:


#include <stdio.h>

int main()
{
    int a;
    a = 0;
    while (a <= 100)
    {
        printf("Value in variable a now is : %d \n", a);
        a = a + 10;
    }
    getchar();
    return 0;
}


If you run this program, it will produce a table of values of variable a. The output will look like this:

Value in variable a now is : 0
Value in variable a now is : 10
Value in variable a now is : 20
Value in variable a now is : 30
Value in variable a now is : 40
Value in variable a now is : 50
Value in variable a now is : 60
Value in variable a now is : 70
Value in variable a now is : 80
Value in variable a now is : 90
Value in variable a now is : 100
Next Page >>
<< Back to Electronics