Skip to content

4.5 - if / if文 (1.9) #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1.9/en/book/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 more traditional
systems language. So let’s talk about it, to make sure you grasp the nuances.

`if` is a specific form of a more general concept, the ‘branch’. The name comes
`if` is a specific form of a more general concept, the ‘branch’, whose name comes
from a branch in a tree: a decision point, where depending on a choice,
multiple paths can be taken.

Expand Down
37 changes: 14 additions & 23 deletions 1.9/ja/book/if.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,62 @@
<!-- 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 more traditional -->
<!-- systems language. So let’s talk about it, to make sure you grasp the nuances. -->
Rustにおける `if` の扱いはさほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれに比べて、
動的型付け言語でみられる `if` にずっと近いものになっています。そのニュアンスをしっかり理解できるよう、
さっそく説明していきましょう。
Rustにおける `if` の扱いは さほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれと比べて、
動的型付け言語の `if` により近いものになっています。そのニュアンスをしっかり理解できるように、説明しましょう。

<!-- `if` is a specific form of a more general concept, the ‘branch’. The name comes -->
<!-- `if` is a specific form of a more general concept, the ‘branch’. whose name comes -->
<!-- from a branch in a tree: a decision point, where depending on a choice, -->
<!-- multiple paths can be taken. -->
`if` は一般化されたコンセプト、「分岐(branch)」の特別な形式です。この名前は木の枝(branch)を由来とし:
取りうる複数のパスから、選択の決定を行うポイントを表します
`if` は より一般的なコンセプトの一つである、「分岐(branch)」の具体的な形です。この名称は、木の枝(branch)に由来します:
決定点はひとつの選択に依存し、複数のパスを取ることができます

<!-- In the case of `if`, there is one choice that leads down two paths: -->
`if` の場合は、続く2つのパスから1つを選択します
`if` の場合は、二つのパスを導く ひとつの選択があります

```rust
let x = 5;

if x == 5 {
# // println!("x is five!");
println!("x は 5 です!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust コードブロック中の # // で始まるコメント行は、削除しないで残してください。 (これ以降、他のコメント行についても同様です) こうしておくと、コードブロックの「Run」ボタンを押してエディタが開いたときに、そこに、原文と和文の両方のコメントが表示されます。

参考:CONTRIBUTING.md

ustのコードブロック(バッククォート3つで始まる別行立てのもの)中のコメントについては行頭が# //になるようにして英文のコメントを含むコードをコメントアウトし、直下にコメントを翻訳したものを書く(See Issue #13)。

}
```

<!-- If we changed the value of `x` to something else, this line would not print. -->
<!-- More specifically, if the expression after the `if` evaluates to `true`, then -->
<!-- the block is executed. If it’s `false`, then it is not. -->
仮に `x` を別の値へと変更すると、この行は表示されません。より正確に言うなら、
`if` のあとにくる式が `true` に評価された場合に、ブロックが実行されます。
`false` の場合、ブロックは実行されません。
もし、`x` を別の値に変更すると、この行は出力されません。よりわかりやすく説明すると、
`if` のあとにくる式が `true` に評価された場合、そのブロックが実行されます。また、`false` の場合は、それは実行されません。

<!-- If you want something to happen in the `false` case, use an `else`: -->
`false` の場合にも何かをしたいなら、 `else` を使います:
`false` の場合にも何かをしたい時は、 `else` を使います:

```rust
let x = 5;

if x == 5 {
# // println!("x is five!");
println!("x は 5 です!");
} else {
# // println!("x is not five :(");
println!("x は 5 ではありません :(");
}
```

<!-- If there is more than one case, use an `else if`: -->
場合分けが複数あるときは、 `else if` を使います:
複数の条件がある時は、 `else if` を使います:

```rust
let x = 5;

if x == 5 {
# // println!("x is five!");
println!("x は 5 です!");
} else if x == 6 {
# // println!("x is six!");
println!("x は 6 です!");
} else {
# // println!("x is not five or six :(");
println!("x は 5 でも 6 でもありません :(");
}
```

<!-- This is all pretty standard. However, you can also do this: -->
全くもって普通ですね。しかし、次のような使い方もできるのです:
これは当然なことですが、次のように書くこともできます:

```rust
let x = 5;
Expand All @@ -80,7 +72,7 @@ let y = if x == 5 {
```

<!-- Which we can (and probably should) write like this: -->
次のように書くこともできます(そして、大抵はこう書くべきです):
また、次のように書くのがほとんどの場合良いでしょう:

```rust
let x = 5;
Expand All @@ -91,6 +83,5 @@ let y = if x == 5 { 10 } else { 15 }; // y: i32
<!-- This works because `if` is an expression. The value of the expression is the -->
<!-- value of the last expression in whichever branch was chosen. An `if` without an -->
<!-- `else` always results in `()` as the value. -->
これが出来るのは `if` が式であるためです。その式の値は、選択された分岐中の最後の式の値となります。
`else` のない `if` では、その値は常に `()` となります。

これが出来るのは `if` が式だからです。その式の値は、選択された条件の最後の式の値です。
`else` のない `if` では、その値は常に `()` になります。
12 changes: 0 additions & 12 deletions diff-1.6.0..1.9.0/src/doc/book/if.md

This file was deleted.