C++ examples for Statement:while
Guess a number using "while" loop
#include <iostream> using namespace std; int main() {//w w w . ja v a 2 s .c o m int secret = 15; int guess = 0; // "!=" is the "not-equal" conditional: while(guess != secret) { // Compound statement cout << "guess the number: "; cin >> guess; } cout << "You guessed it!" << endl; }