Break statement exiting a for statement - C++ Statement

C++ examples for Statement:break

Description

Break statement exiting a for statement

Demo Code

#include <iostream>

int main(int argc, const char *argv[]) {
    int count;// ww  w.  j av  a2 s. com

    for (count = 1; count <= 10; ++count) {
        if (count == 5) break;

        std::cout << count << " ";
    }

    std::cout << "\nBroke out of loop at count = " << count << std::endl;
    return 0;
}

Result


Related Tutorials