나의 작은 valley
[C언어] 루프 탈출조건 do-while문 본문
728x90
//do-while문이 유용한 경우
#include <stdio.h>
int main()
{
const int secret_code = 337;
int guess = 0;
//비효율적인 코드
//printf("Enter secret code : ");
//scanf("%d", &guess);
//while (guess != secret_code)
//{
// printf("Enter secret code : ");
// scanf("%d", &guess);
//}
//printf("welcome home!");
//효율적인 코드, do-while문
//비교 전에 한번 실행한다는 특징이 있다.
do
{
printf("Enter secret code : ");
scanf("%d", &guess);
} while (guess != secret_code);
printf("welcome home!");
return 0;
}
//do-while문 순서도
728x90
'Computer Science > [C언어] 문법 정리' 카테고리의 다른 글
[C언어] 분기문 if, 다중 선택(else if) (0) | 2022.09.14 |
---|---|
[C언어] 배열, 루프에 대한 자세한 이해, 런타임 에러 (0) | 2022.09.13 |
[C언어] 콤마 연산자 (0) | 2022.09.13 |
[C언어] 간단한 어셈블리 코드 확인법 (0) | 2022.09.13 |
[C언어] _Bool 자료형 (0) | 2022.09.13 |
Comments