Loop Control: break & continue

🟢 Beginner

📖 Definition

break immediately terminates the innermost enclosing loop. continue skips remaining statements in the current iteration and jumps directly to the loop condition evaluation.

💡 Code Example

#include <iostream>

int main() {
    for (int i = 1; i <= 10; ++i) {
        if (i == 3) continue; // Skip 3
        if (i == 7) break;    // Stop at 7
        std::cout << i << " ";
    }
    std::cout << "\n";
    return 0;
}

👀 Output

1 2 4 5 6