Cambo Freelance
HomeServicesArticlesTutorialsTeamCoursesContact
Cambo Freelance

Professional freelance team from Cambodia delivering technology-driven solutions with cultural insight and modern expertise.

Send us a message

Ready to start your project? Get in touch with our team.

Contact Us

Services

  • Web & Mobile Development Services
  • Graphic Design & Branding Services

Useful Links

  • Home
  • Services
  • Learning
  • About Us
  • Contact
  • Pricing

© 2026 Cambo Freelance. រក្សាសិទ្ធិទាំងអស់។

TelegramFacebookLinkedInEmail
HomeTutorialsC++C++ Break and Continue
⚡C++ Tutorials

50 lessons

Beginner(21)1C++ Introduction2C++ Getting Started3C++ Syntax4C++ Output5C++ Comments6C++ Variables7C++ Data Types8C++ Constants9C++ User Input10C++ Operators11C++ Strings12C++ Math13C++ Booleans14C++ Conditions15C++ Switch16C++ Loops17C++ Break and Continue18C++ Arrays19C++ Functions20C++ References21C++ Pointers
Intermediate(19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers
Advanced(10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44
⚡

C++ Tutorials

Lesson 17 of 50

All lessons
Beginner (21)1C++ Introduction2C++ Getting Started
26
C++ Encapsulation
27C++ Inheritance
28C++ Polymorphism
29C++ Abstraction
30C++ Files
31C++ Exception Handling
32C++ Namespaces
33C++ Structures
34C++ Enumerations
35C++ STL Introduction
36C++ Vectors
37C++ Maps
38C++ Sets
39C++ Queues
40C++ Stacks
C++ Move Semantics
45C++ Multithreading
46C++ Design Patterns
47C++ Memory Management
48C++17 Features
49C++20 Features
50C++ Performance Optimization
3
C++ Syntax
4C++ Output
5C++ Comments
6C++ Variables
7C++ Data Types
8C++ Constants
9C++ User Input
10C++ Operators
11C++ Strings
12C++ Math
13C++ Booleans
14C++ Conditions
15C++ Switch
16C++ Loops
17C++ Break and Continue
18C++ Arrays
19C++ Functions
20C++ References
21C++ Pointers
Intermediate (19)22C++ Classes23C++ Objects24C++ Constructors25C++ Access Specifiers26C++ Encapsulation27C++ Inheritance28C++ Polymorphism29C++ Abstraction30C++ Files31C++ Exception Handling32C++ Namespaces33C++ Structures34C++ Enumerations35C++ STL Introduction36C++ Vectors37C++ Maps38C++ Sets39C++ Queues40C++ Stacks
Advanced (10)41C++ Smart Pointers42C++ Templates43C++ Lambda Functions44C++ Move Semantics45C++ Multithreading46C++ Design Patterns47C++ Memory Management48C++17 Features49C++20 Features50C++ Performance Optimization
⚡C++BeginnerLesson 17 of 50CamboFreelanceJune 19, 2026

C++ Break and Continue

Learn how break and continue control loop execution in C++. See practical examples of stopping loops early and skipping iterations.


Tutorials › C++ › Break & Continue
Beginner5 min readLesson 17 of 50

In This Lesson

  • break
  • continue
  • Nested Loops
  • Quiz

break Statement

break immediately exits the nearest enclosing loop or switch.

#include <iostream>
using namespace std;

int main() {
    for (int i = 1; i <= 10; i++) {
        if (i == 5) break;   // stop when i reaches 5
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Output:

1 2 3 4

continue Statement

continue skips the rest of the current iteration and jumps to the next one.

for (int i = 1; i <= 10; i++) {
    if (i % 2 == 0) continue;   // skip even numbers
    cout << i << " ";
}

Output:

1 3 5 7 9

break in Nested Loops

break only exits the innermost loop it is inside:

for (int i = 1; i <= 3; i++) {
    for (int j = 1; j <= 3; j++) {
        if (j == 2) break;   // exits inner loop only
        cout << i << "," << j << "  ";
    }
    cout << endl;
}

Output:

1,1
2,1
3,1

Exercise

Use a while loop and break to keep asking the user for a number until they enter 0. Print each number entered.

Show Solution
#include <iostream>
using namespace std;

int main() {
    int n;
    while (true) {
        cout << "Enter a number (0 to quit): ";
        cin >> n;
        if (n == 0) break;
        cout << "You entered: " << n << endl;
    }
    cout << "Goodbye!" << endl;
    return 0;
}

Quiz

  1. What does continue do in a loop?

    • A) Exits the loop
    • B) Restarts the program
    • C) Skips the current iteration and goes to the next
    • D) Pauses execution
    Answer

    C) continue skips the remaining code in the current iteration and begins the next one.

  2. If you have nested loops and use break, which loop exits?

    • A) The outermost loop
    • B) All loops
    • C) The innermost loop
    • D) The loop with the break label
    Answer

    C) break exits only the innermost enclosing loop.

Summary

  • break exits the current loop or switch immediately.
  • continue skips the rest of the current iteration.
  • In nested loops, break only exits the innermost loop.
← Previous: Loops Next: C++ Arrays →
c++breakcontinueloopsbeginner
PreviousLesson 16: C++ LoopsNextLesson 18: C++ Arrays
Back to All Tutorials