본문 바로가기
Programming/C

break문과 continue문

by Tarake 2024. 8. 15.

BREAK문


#include<stdio.h>

int main(void) {
    int n = 0;
    while(1) {
        if(n == 4) {
            break;
        }
        n++;
    }
    return 0;
}

break문은 반복문을 탈출하기 위해서 사용됩니다. 반복문 안에서 break문이 실행되면 반복문을 빠져 나오게 됩니다.

 

 

CONTINUE문


#include<stdio.h>

int main(void) {
    int n = 0;
    while(n < 10) {
        if(n == 4) {
            n++;
            continue;
        }
        n++;
    }
    return 0;
}

continue문은 현재 실행하고 있는 반복문의 나머지를 생략하고 다음 반복을 시작하게 합니다.

 

 

 

출처

W3school

 

W3Schools.com

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

'Programming > C' 카테고리의 다른 글

문자열과 boolean  (0) 2024.08.15
배열  (0) 2024.08.15
반복문  (0) 2024.08.14
조건문  (0) 2024.08.14
연산자  (0) 2024.08.14