next up previous
Next: switch Up: Control Structures Previous: for

while


while (ch != 'Q') {
   process();
   cin >> ch;
}
while is more intuitive than for in some cases but you have to initialize variables separately. Compare:

for (double x = 100; x > 2; x = sqrt(x)) 
    cout << x << endl;
  
double x = 100;
while (x > 2) {
    cout << x << endl;
    x = sqrt(x);
}


Andreas Koeller
2000-06-04