AsegGasiaBlog

C Programming - Loop - While Loop

While Loop

while loop statement in C programming language repeatedly executes a target statement as long as a given condition is true.

Syntax :


while( condition )
{
    statement(s);
}

Example :


#include <stdio.h>
int main ()
{
    // local variable definition
    int a = 1;

    // while loop execution
    while( a < 5 )
    {
        //loops comes inside this body, until condition is true
        printf("Value of a: %d\n", a);
        a++;
    }

    return 0;
}

Output :

 Value of a: 1
 Value of a: 2
 Value of a: 3
 Value of a: 4


Popular Posts