Namespaces
Variants

continue statement

From cppreference.net
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements (loops)
Jump statements
continue - break
Functions
Function declaration
Lambda function expression
inline specifier
Dynamic exception specifications ( until C++17* )
noexcept specifier (C++11)
Exceptions
Namespaces
Types
Specifiers
constexpr (C++11)
consteval (C++20)
constinit (C++20)
Storage duration specifiers
Initialization
Expressions
Alternative representations
Literals
Boolean - Integer - Floating-point
Character - String - nullptr (C++11)
User-defined (C++11)
Utilities
Attributes (C++11)
Types
typedef declaration
Type alias declaration (C++11)
Casts
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
Miscellaneous

나머지 부분의 바깥쪽 for , range-for , while 또는 do-while 루프 본문이 건너뛰어지도록 합니다.

조건문을 사용하여 루프의 나머지 부분을 무시하는 것이 어색한 경우에 사용됩니다.

목차

구문

attr  (선택 사항) continue ;

설명

continue 문은 마치 goto 를 사용한 것처럼 루프 본문의 끝으로 점프를 발생시킵니다 (이 문은 for , range-for , while , do-while 루프의 본문 내에서만 나타날 수 있습니다).

보다 정확하게는,

while 루프의 경우, 다음과 같이 동작합니다

while (/* ... */)
{
   // ...
   continue; // goto contin;으로 동작함
   // ...
   contin:;
}

do-while 루프의 경우, 다음과 같이 동작합니다:

do
{
    // ...
    continue; // contin:로의 goto처럼 동작함
    // ...
    contin:;
} while (/* ... */);

for 루프와 range-for 루프의 경우, 다음과 같이 동작합니다:

for (/* ... */)
{
    // ...
    continue; // contin:로의 goto처럼 동작함
    // ...
    contin:;
}

키워드

continue

예제

#include <iostream>
int main()
{
    for (int i = 0; i < 10; ++i)
    {
        if (i != 5)
            continue;
        std::cout << i << ' ';      // 이 문장은 i != 5일 때마다 건너뜀
    }
    std::cout << '\n';
    for (int j = 0; 2 != j; ++j)
        for (int k = 0; k < 5; ++k) // continue는 이 루프에만 영향을 줌
        {
            if (k == 3)
                continue;
            // 이 문장은 k == 3일 때마다 건너뜀:
            std::cout << '(' << j << ',' << k << ") ";
        }
    std::cout << '\n';
}

출력:

5
(0,0) (0,1) (0,2) (0,4) (1,0) (1,1) (1,2) (1,4)

참고 항목

C 문서 에 대한 continue