C++ whil while loop

while while e 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 <iostream>
using namespace std;
int main ()
{
    // local variable definition
    int a = 1;

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

    return 0;
}

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


0 Comments