#include <stdio.h>
int main() {
int i=1;
int sq;
while(i<=10) {
sq = i*i;
printf("square of %d is %d.\n", i, sq);
i = i+1;
}
scanf("%d", &i);
return 1;
}
In the example given above initial value of i is 1. then boolean expression inside while loop is i<=10 which evaluates to true because i is 1, Hence all statements inside loop will be executed. See that we are increasing value of i inside loop by 1. Again boolean statement will be true because i is 2. Similarly program will continue. When value of i will reach 11, boolean statement will be false and program will go out of while loop. Try to run this program to see the output.In next topic we will learn to use string and see some interesting examples.
If you like this tutorial, share it with your friends on facebook, orkut, twitter etc.