C While Loop

The While Loop is most basic loop in C language. It is used to execute a specific block of code repeatedly as long as the given condition is true. In while loop the condition will checked first and If condition become true, execute a block of code executed. Syntax :
while ( condition is true ) {
  code to be executed
}
Example 1 : The below code will print "Hello world" five times.
#include <stdio.h>

int main() {
  int count = 0;

  while(count < 5) {
    printf("Hello world\n");
    count++;
  }

  return 0; 
}
Output :

Hello world
Hello world
Hello world
Hello world
Hello world

Example 2 : The next example will print the table of 2.
#include <stdio.h>

int main() {
  int count = 1, num = 2;

  while(count <= 10) {
    printf("%d\n", count*num);
    count++;
  }

  return 0;
}
Output :

2
4
6
8
10
12
14
16
18
20

Next Topic :