C++ examples for Statement:while
Using a while loop
#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; }