Break statement causes a loop to end immediately, instead of waiting for its condition to be false. - C++ Statement

C++ examples for Statement:break

Description

Break statement causes a loop to end immediately, instead of waiting for its condition to be false.

Demo Code

#include <iostream> 
 
int main() /*from www  . j  a  v  a  2  s .  c o m*/
{ 
    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; 
}

Result


Related Tutorials