Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Programming
- python
- W3Schools
- dfs
- Unity
- 문제풀이
- Basic
- 백준
- Class
- loop
- String
- dynamic
- Algorithm
- c++
- 기초
- 시작해요 언리얼 2022
- Material
- 재귀
- Unreal Engine 5
- 오류
- UE5
- guide
- github
- w3school
- parameter
- Tutorial
- 프로그래밍
- 파이썬
- DP
- C#
Archives
- Today
- Total
행복한 개구리
C++ Tutorial - Conditions / Else 본문

else 선언문
조건이 false 일 때 코드 블럭을 실행시키려면 else 선언을 사용하세요.
문법
if (condition) {
// condition이 참일 때 실행되는 코드 블럭
} else {
// condition이 거짓일 때 실행되는 코드 블럭
}
예시
#include <iostream>
using namespace std;
int main() {
int time = 20;
if (time < 18) {
cout << "Good day.";
}
else {
cout << "Good evening.";
}
}

예시 설명
위 예시에서 time(20)은 18보다 큽니다. 따라서 조건은 false 이므로 우리는 else 조건으로 이동하여 화면에 "Good evening."을 출력한 것입니다. 만약 time이 18보다 작았다면 프로그램은 "Good day."를 출력했을 것입니다.
'C++ > 공부내용' 카테고리의 다른 글
| C++ Tutorial - Switch (0) | 2022.06.16 |
|---|---|
| C++ Tutorial - Conditions / Short Hand If Else (0) | 2022.06.14 |
| C++ Tutorial - Conditions / If (0) | 2022.06.14 |
| C++ Tutorial - Booleans / Boolean Expressions (0) | 2022.06.14 |
| C++ Tutorial - Booleans / Boolean Values (0) | 2022.06.14 |