{ A destination to learn coding }

Iteration Statements

While Loop

The while loop consists of only one expression.
While loop continues to iterate until the condition is false.

Syntax:

while(condition)
{
 statement;
}

Re-writing the for loop's Hellow world program using while loop
#include<stdio.h>
int main()
{
 int i=0;

 while(i<10)
 {
  printf("Hello World\n");
  i++;
 }
 printf("Done");

 return 0;

}

Analyzing the code above

i is declared and initialized to 0
i is used as a loop control variable.
While i<10, the condition is true and the statement is executed.
Statement prints Hello World and i is incremented.
The loop terminates when i<10 is false.
The program control is passed to the code line which is immediately after the while loop.

Try this
#include<stdio.h>
int main()
{
  int a=1;

  while(a!=10)
  {
    printf("\nEnter a number\n");
    scanf("%d",&a);
  }

  printf("You entered 10\n");

  return 0;
}

Remember that a condition can be anything. If its true, the loop will iterate, if its false the loop will terminate.

Try this
Printing table of any number
Display first 10 natural numbers
Find factorial of a number
Code to check for a prime number.
Fibonacci Series
You can even try printing patterns
C Codes