Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
79 views
in C++ by (155k points)
edited by
What happens if multiple loops are nested, and a break statement is encountered in C++?

Please log in or register to answer this question.

1 Answer

0 votes
by (155k points)

When a break statement is encountered in nested loops, it will only terminate the innermost loop and resume execution with the next statement after that loop. The outer loops will continue their execution.

Example:

for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
        if (i == 2 && j == 2) {
            break;  // Terminates the inner loop when i equals 2 and j equals 2
        }
        cout << i << "-" << j << " ";
    }
}
// Output: 1-1 1-2 1-3 3-1 3-2 3-3

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jun 2, 2023 in C++ by kvdevika (155k points)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...