# 조건문 - 만약

### 코드

{% code title="조건이 참일 때만 실행" %}

```
만약 {조건} 이면
    {조건 충족 시 실행할 코드}
```

{% endcode %}

{% code title="조건이 참일 때 / 거짓일 때 실행" %}

```
만약 {조건} 이면
    {조건 충족 시 실행할 코드}
아니면
    {조건 미충족 시 실행할 코드}
```

{% endcode %}

{% code title="조건이 참일 때 / 다른 조건이 참일 때 실행" %}

```
만약 {조건1} 이면
    {조건1 충족 시 실행할 코드}
아니면 만약 {조건2} 이면
    {조건2 충족 시 실행할 코드}
```

{% endcode %}

{% code title="조건이 참일 때 / 다른 조건이 참일 때 / 거짓일 때 실행" %}

```
만약 {조건1} 이면
    {조건1 충족 시 실행할 코드}
아니면 만약 {조건2} 이면
    {조건2 충족 시 실행할 코드}
아니면
    {모든 조건 미충족 시 실행할 코드}
```

{% endcode %}

이 외에도 여러 다양한 조합으로 사용할 수 있어요.

***

### 설명

<mark style="color:purple;">`만약`</mark>은 조건에 따라 원하는 코드를 실행하고 싶을 때 사용해요.

<mark style="color:purple;">`만약`</mark>은 필수지만, <mark style="color:purple;">`아니면 만약`</mark>과 아니면은 필수가 아니예요. <mark style="color:purple;">`만약`</mark> + <mark style="color:purple;">`아니면 만약`</mark> 조합, <mark style="color:purple;">`만약`</mark> + <mark style="color:purple;">`아니면`</mark> 조합, <mark style="color:purple;">`만약`</mark> + <mark style="color:purple;">`아니면 만약`</mark> + <mark style="color:purple;">`아니면`</mark> 조합 등 다양하게 조합해 사용할 수 있어요.

***

### 주의사항

* <mark style="color:purple;">`아니면 만약`</mark>은 여러 번 사용할 수 있지만, <mark style="color:purple;">`아니면`</mark>은 한 번만 사용할 수 있어요. 아래 예시를 참고해 주세요.

{% code title="사용할 수 없는 예시" %}

```
만약 1 == 2 이면
    "안녕" 보여주기
아니면
    "아닌데?" 보여주기
아니면
    "아니라고!" 보여주기
```

{% endcode %}

***

### 파이썬 대응 코드

```
if 1 > 2:
    print("1은 2보다 커")  # [출력하는 것으로, 조건문과 무관합니다]
elif 1 == 2:
    print("1은 2랑 같아!")  # [출력하는 것으로, 조건문과 무관합니다]
else:
    print("1은 2보다 작아!")  # [출력하는 것으로, 조건문과 무관합니다]
```

<mark style="color:purple;">`만약`</mark>은 <mark style="color:purple;">`if`</mark>와, 아니면 <mark style="color:purple;">`만약`</mark>은 <mark style="color:purple;">`elif`</mark>랑, <mark style="color:purple;">`아니면`</mark>은 <mark style="color:purple;">`else`</mark>랑 같아요.

***

### 예시

{% code title="예시 코드" %}

```
만약 1 > 2 이면
    "1은 2보다 커!" 보여주기  # [출력하는 것으로, 조건문과 무관합니다]
아니면 만약  1 == 2 이면
    "1은 2랑 같아!" 보여주기  # [출력하는 것으로, 조건문과 무관합니다]
아니면
    "1은 2보다 작아!" 보여주기  # [출력하는 것으로, 조건문과 무관합니다]
```

{% endcode %}

{% code title="예시 코드의 출력" %}

```
1은 2보다 작아!
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://codebook.horang.it/readme/008.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
