# If Else

> Let's learn about Go's conditional statement

\ <br>

### If

* Use if to express conditional statements
  * ex)

    ```go
    package main

    import "fmt"

    func canIDrink(age int) bool {
     if age < 18 {
      return false
     }
     return true
    }

    func main() {
     fmt.Println(canIDrink(19))
    }

    ```

<br>

### Variable expression

* You can create a variable at the moment you use if
  * You can create a variable right inside the if, and use that variable right after the semicolon(`;`)
  * ex)

    ```go
    package main

    import "fmt"

    func canIDrive(age int) bool {
     // create a variable right incide of the "if"
     if koreanAge := age + 2; koreanAge < 18 {
      return false
     }
     return true
    }

    func main() {
     fmt.Println(canIDrive(20))
    }
    ```
  * By doing this, you can let other people reading the code know that *"the variable was created only for use in if-else conditions!"*


---

# 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://chloe-codes1.gitbook.io/til/go/go-101/05_if_else.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.
