C++ 기타


else 문

else조건이 인 경우 실행할 코드 블록을 지정 하려면 명령문을 사용하십시오 false.

통사론

if (condition) {
  // block of code to be executed if the condition is true
} else {
  // block of code to be executed if the condition is false
}

예시

int time = 20;
if (time < 18) {
  cout << "Good day.";
} else {
  cout << "Good evening.";
}
// Outputs "Good evening."

설명된 예

위의 예에서 시간(20)은 18보다 크므로 조건은 false입니다. 이 때문에 else조건으로 이동하여 "좋은 저녁" 화면에 인쇄합니다. 시간이 18보다 작으면 프로그램은 "좋은 날"을 인쇄합니다.