Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Repeats a block as long as the condition is true. The condition is checked before each iteration, so the body may never execute.
while (condition) {
// body
// must update condition!
}int n = 12345, count = 0;
while (n > 0) {
count++;
n /= 10;
}
// count = 5int x;
while (cin >> x) {
// process x
}Always ensure the loop condition will eventually become false. Forgetting to update the variable causes an infinite loop.