C++ examples for Statement:while
Use while loop to print out the powers of 2 less than 1000.
#include <iostream> #include <cmath> using namespace std ; int main(){//from w w w.j a v a 2s . c o m int count = 0; int currentPower = 1; while ( currentPower <1000) { cout << "2^" << count << "="; cout << currentPower ; cout << "\n"; currentPower *= 2; count ++; } return 0; }