while Loop - Devbhoomi

FREE JOB ALERT & ONLINE TUTORIALS

Hot

Post Top Ad

Sunday 5 November 2017

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

No comments:

Post a Comment

Post Top Ad