`continue` — C++ Keyword

`continue` — C++ Keyword

The continue keyword in C++: skips the rest of the current loop iteration.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

continue

Skips the remainder of the current loop body and jumps to the next iteration. Works in for, while, and do/while loops.

Syntax

continue;

Example

#include <print>

int main() {
    // Skip even numbers
    for (int i = 0; i < 10; ++i) {
        if (i % 2 == 0) continue;
        std::print("{} ", i);   // 1 3 5 7 9
    }
    std::println();

    // In a while loop
    int n = 0;
    while (n < 6) {
        ++n;
        if (n == 3) continue;   // skip printing 3
        std::print("{} ", n);   // 1 2 4 5 6
    }
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}