UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study while loop

C program to study while loop

by Krishna


Posted on 27 Jul 2018 Category: C Views: 18

Edited on 18 Jul 2019


C program to study while loop

C while loops statement allows to repeatedly run the same block of code until a condition is met. while loop is a most basic loop in C programming. 
while loop has one control condition, and executes as long the condition is true.

The syntax of a while loop in C programming language is −

while(condition) {
   statement(s);
}

Below shows a sample while loop program and its output

#include <stdio.h>

int main()
{
    int i, n=5;

    

    /*
     * Print natural numbers from 1 to n
     */
    i=1;
    while(i<=n)
    {
        printf("%d\n", i);
        i++;
    }

    return 0;
}

OUTPUT



Leave a Comment: