C Language

May 15, 2023

How to use while loop in C Language

Program to use while loop in C Language


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

Output


1 2 3 4 5
  1. Declare integer variable
  2. Initialize in integer variable i = 1
  3. While(i<=5) condition which needs to be evaluated
  4. pintf inbuild function to display the value of %d
  5. code of instructions which needs to be executed
  6. i++increment value

by : Nadeem Khan

Quick Summary:

While loop