Skip to content
Justice Tech School

while, do while and break

while checks before, do while checks after. break and continue control loops.

Example
int n = 3;
while (n > 0) cout << n-- << " ";
cout << "\n";
int i = 0;
do { i++; } while (i < 3);
cout << i << "\n";
for (int j = 0; j < 10; j++) { if (j % 2) continue; if (j > 6) break; cout << j << " "; }
cout << "\n";

Result

3 2 1 
3
0 2 4 6 

Exercise

Run at least once.

 { } while (x);

Quiz Test

Which loop tests after the body?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.