How to use while loop in c language

While Loop

On this page

While Loop

Program to use while loop is c language

#include <stdio.h>
  int main()
  {
    int i = 1;
    while (i <= 10)
    {
        printf("%d\t", i);
        i = i + 1;
    }
    printf("\n");
    return 0;
  }
  

Output

1       2       3       4       5       6       7       8       9       10
  

Steps Description

  • Declare integer variable i
  • initialize integer variable i = 1
  • whil (i = 5) condition which needs to be evaluated
  • printf inbuild function to display the value of %d
  • code of instructions which need to be executed
  • i++ increment value