Using a while loop - C++ Statement

C++ examples for Statement:while

Description

Using a while loop

Demo Code

#include <iostream> 
#include <stdlib.h> 

using namespace std; 

int main(int argc, char *argv []) 
{ 
    int anInt; /*from   www . j a  v  a  2s.c o m*/

    // Prompt the user for an integer. 
    cout << "Please input an integer and press Enter: "; 
    cin >> anInt; 

    int i=0; 
    while (i < anInt) 
    { 
    cout << i++ << endl; 
    } 

  
    return 0; 
}

Result


Related Tutorials