The break statement causes a loop to end immediately.
This statement appears inside a loop.
#include <iostream> int main() /* www . j a v a2 s. c om*/ { int counter = 0; int multiples = 0; while (true) { counter++; if (counter % 14 == 0) { std::cout << counter << " "; multiples++; } if (multiples > 19) break; } std::cout << "\n"; return 0; }
A counter variable is incremented from 0 upward, and every time the variable is evenly divisible by 14, its value is displayed.
The break statement causes the loop to end.