### Updated if.md

revision cdbb723caff7b7b3f8a5a2e0b2f0a17653e1c5f8
if
# if.md

Write here..
2.5. 만약에 (If)

Rust's take on `if` is not particularly complex, but it's much more like the
`if` you'll find in a dynamically typed language than in a 더 전통적인 시스템 언어. 이에 대해 더 이야기해봅시다, to make sure you grasp the nuances.

`if`는 일반적인 개념인 *분기(branch)*의구체화된 형식입니다. 나무의 가지에서 이름을 따왔고, 선택에따라 다양한 경로가 취해질 수 있는 결정 포인트 역할을 합니다.

`if`의 경우, 하나의 결정에 두개의 경로가 따라옵니다.

```rust
let x = 5;

if x == 5 {
println!("x is five!");
}
```

만약 무언가 하기 위해 `x`의 값을 변경했다면, 이 라인은 출력되지 않을 것입니다. 더 자세히, 만약 `if` 다음에 오는 식이 `true`으로 평가된다면, 블록은 실행됩니다. `false`라면, 그렇지 못합니다.

`false`인 경우에 어떤일이 벌어지길 원한다면, `else`를 사용하세요.

```{rust}
let x = 5;

if x == 5 {
println!("x is five!");
} else {
println!("x is not five :(");
}
```

If there is more than one case, use an `else if`:

```rust
let x = 5;

if x == 5 {
println!("x is five!");
} else if x == 6 {
println!("x is six!");
} else {
println!("x is not five or six :(");
}
```

이렇게 하는 것은 정말 표준적인 방식입니다. 하지만, 이렇게도 할 수 있습니다.

```{rust}
let x = 5;

let y = if x == 5 {
10
} else {
15
}; // y: i32
```

또는 이와 같이 작성할 수도 있습니다.

```{rust}
let x = 5;

let y = if x == 5 { 10 } else { 15 }; // y: i32
```

This reveals two interesting things about Rust: it is an expression-based
language, and semicolons are different from semicolons in other 'curly brace
and semicolon'-based languages. These two things are related.

## 표현식 vs. 구문

Rust은 기본적으로 표현식 기반 언어입니다. There are only two kinds of
statements, and everything else is an expression.

So what's the difference? Expressions return a value, and statements do not.
In many languages, `if` is a statement, and therefore, `let x = if ...` would
make no sense. But in Rust, `if` is an expression, which means that it returns
a value. We can then use this value to initialize the binding.

Speaking of which, bindings are a kind of the first of Rust's two statements.
The proper name is a *declaration statement*. So far, `let` is the only kind
of declaration statement we've seen. Let's talk about that some more.

In some languages, variable bindings can be written as expressions, not just
statements. Like Ruby:

```{ruby}
x = y = 5
```

In Rust, however, using `let` to introduce a binding is _not_ an expression. The
following will produce a compile-time error:

```{ignore}
let x = (let y = 5); // expected identifier, found keyword `let`
```

The compiler is telling us here that it was expecting to see the beginning of
an expression, and a `let` can only begin a statement, not an expression.

Note that assigning to an already-bound variable (e.g. `y = 5`) is still an
expression, although its value is not particularly useful. Unlike C, where an
assignment evaluates to the assigned value (e.g. `5` in the previous example),
in Rust the value of an assignment is the unit type `()` (which we'll cover later).

The second kind of statement in Rust is the *expression statement*. Its
purpose is to turn any expression into a statement. In practical terms, Rust's
grammar expects statements to follow other statements. This means that you use
semicolons to separate expressions from each other. This means that Rust
looks a lot like most other languages that require you to use semicolons
at the end of every line, and you will see semicolons at the end of almost
every line of Rust code you see.

What is this exception that makes us say "almost"? You saw it already, in this
code:

```{rust}
let x = 5;

let y: i32 = if x == 5 { 10 } else { 15 };
```

Note that I've added the type annotation to `y`, to specify explicitly that I
want `y` to be an integer.

This is not the same as this, which won't compile:

```{ignore}
let x = 5;

let y: i32 = if x == 5 { 10; } else { 15; };
```

Note the semicolons after the 10 and 15. Rust will give us the following error:

```text
error: mismatched types: expected `i32`, found `()` (expected i32, found ())
```

We expected an integer, but we got `()`. `()` is pronounced *unit*, and is a
special type in Rust's type system. In Rust, `()` is _not_ a valid value for a
variable of type `i32`. It's only a valid value for variables of the type `()`,
which aren't very useful. Remember how we said statements don't return a value?
Well, that's the purpose of unit in this case. The semicolon turns any
expression into a statement by throwing away its value and returning unit