logo

C 계속문

그만큼 계속 진술 C 언어에서는 프로그램 제어를 루프의 시작 부분으로 가져오는 데 사용됩니다. continue 문은 루프 내부의 일부 코드 줄을 건너뛰고 다음 반복을 계속합니다. 특정 조건에 대한 일부 코드를 건너뛸 수 있도록 조건에 주로 사용됩니다.

통사론:

 //loop statements continue; //some lines of the code which is to be skipped 

계속 진술 예시 1

 #include void main () { int i = 0; while(i!=10) { printf('%d', i); continue; i++; } } 

산출

 infinite loop 

계속 진술 예시 2

 #include int main(){ int i=1;//initializing a local variable //starting a loop from 1 to 10 for(i=1;i<=10;i++){ if(i="=5){//if" value of i is equal to 5, it will continue the loop continue; } printf('%d 
',i); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 2 3 4 6 7 8 9 10 </pre> <p>As you can see, 5 is not printed on the console because loop is continued at i==5.</p> <h2>C continue statement with inner loop</h2> <p>In such case, C continue statement continues only inner loop, but not outer loop.</p> <pre> #include int main(){ int i=1,j=1;//initializing a local variable for(i=1;i<=3;i++){ for(j="1;j&lt;=3;j++){" if(i="=2" && j="=2){" continue; will continue loop of only } printf('%d %d
',i,j); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <p>As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.</p> <hr></=3;i++){></pre></=10;i++){>

보시다시피 i==5에서 루프가 계속되기 때문에 5가 콘솔에 인쇄되지 않습니다.

내부 루프가 있는 C continue 문

이러한 경우 C continue 문은 내부 루프만 계속하고 외부 루프는 계속하지 않습니다.

 #include int main(){ int i=1,j=1;//initializing a local variable for(i=1;i<=3;i++){ for(j="1;j&lt;=3;j++){" if(i="=2" && j="=2){" continue; will continue loop of only } printf(\'%d %d
\',i,j); end for return 0; < pre> <p> <strong>Output</strong> </p> <pre> 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3 </pre> <p>As you can see, 2 2 is not printed on the console because inner loop is continued at i==2 and j==2.</p> <hr></=3;i++){>

보시다시피 2 2 는 i==2 및 j==2에서 내부 루프가 계속되기 때문에 콘솔에 인쇄되지 않습니다.