continue 문 (C++)

제어를 가장 작은 바깥쪽의 제어 식( for 또는 while 루프)으로 강제로 전송합니다.

구문

continue;

설명

현재 반복에서 나머지 모든 문은 실행되지 않습니다. 루프의 다음 반복은 다음과 같이 결정됩니다.

  • do 또는 while 루프에서 다음 반복은 or while 문의 제어 식을 do 다시 평가하여 시작합니다.

  • for 루프에서(구문을 for( <init-expr> ; <cond-expr> ; <loop-expr> )사용하여) 절이 <loop-expr> 실행됩니다. 그런 다음 <cond-expr> 절이 다시 계산되고 해당 결과에 따라 루프가 종료되거나 다른 반복이 발생합니다.

다음 예제에서는 문을 사용하여 코드 섹션을 바이패스하고 루프의 다음 반복을 시작하는 방법을 continue 보여줍니다.

예시

// continue_statement.cpp
#include <stdio.h>
int main()
{
    int i = 0;
    do
    {
        i++;
        printf_s("before the continue\n");
        continue;
        printf("after the continue, should never print\n");
     } while (i < 3);

     printf_s("after the do loop\n");
}
before the continue
before the continue
before the continue
after the do loop

참고 항목

점프 문
키워드