Namespaces
Variants
Views
Actions

continue statement

From cppreference.com
 
 
C++ language
General topics
Preprocessor
Comments
Keywords
ASCII chart
Escape sequences
History of C++
Flow control
Conditional execution statements
Iteration statements
Jump statements
continue statement
break statement
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 

Causes the remaining portion of the enclosing for, range-for, while or do-while loop body skipped.

Used when it is otherwise awkward to ignore the remaining portion of the loop using conditional statements.

Contents

[edit] Syntax

continue

[edit] Explanation

This statement works as a shortcut to the end of the enclosing loop body.

In case of while or do-while loops, the next statement executed is the condition check (cond_expression). In case of for loop, the next statements executed are the iteration expression and condition check (iteration_expression, cond_expression). After that the loop continues as normal.

[edit] Keywords

continue

[edit] Example

#include <iostream>
 
int main() 
{
    for (int i = 0; i < 10; i++) {
        if (i != 5) continue;
        std::cout << i << " ";       //this statement is skipped each time i!=5
    }
 
    std::cout << '\n';
 
    for (int j = 0; j < 2; j++) {
        for (int k = 0; k < 5; k++) {   //only this loop is affected by continue
            if (k == 3) continue;
            std::cout << j << k << " "; //this statement is skipped each time k==3
        }
    }
}

Output:

5
00 01 02 04 10 11 12 14