본문 바로가기
C/☞

[19] 반복문 : while

by TR. 2020. 7. 14.

. 무한반복

 

# include <Windows.h>
# include <stdio.h>

void main(){
	
	while(0){
		printf("무한반복\n");
	}

	system("pause");
}

 

. 반복제어

 

# include <Windows.h>
# include <stdio.h>

void main(){
	// 5번 반복
	int n = 0;				// 초기식
	while(n < 5){				// 조건식
		printf("반복\n");
		n = n + 1;			// 증감식
	}


	system("pause");
}

 


매크로 상수 정의를 통해 boolean 사용

 

#include <stdio.h>
// #define TRUE 1
// #define FALSE 0

int main(){
    // if(TRUE){
    if(true){ // 매크로 상수를 사용하지 않아도, C/C++표준에서 true & false를 정의하고 있음
        printf("[%d]\n", 1000);
    }



    return 0;
}

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

[21] 반복문 : for  (0) 2020.07.14
[20] 연습문제 : while  (0) 2020.07.14
[18] 반복문  (0) 2020.07.14
[17]-A. 로그인 처리  (0) 2020.07.14
[17] 로그인 처리  (0) 2020.07.14

댓글