Skip to content

Commit 561a4b1

Browse files
committed
translate if.md
1 parent 8336dbd commit 561a4b1

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

1.6/ja/book/if.md

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,66 @@ Rustにおける `if` の扱いはさほど複雑ではありませんが、伝
88
動的型付け言語でみられる `if` にずっと近いものになっています。そのニュアンスをしっかり理解できるよう、
99
さっそく説明していきましょう。
1010

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

15-
In the case of `if`, there is one choice that leads down two paths:
17+
<!-- In the case of `if`, there is one choice that leads down two paths: -->
18+
`if` の場合は、続く2つのパスから1つを選択します。
1619

1720
```rust
1821
let x = 5;
1922

2023
if x == 5 {
21-
println!("x is five!");
24+
# // println!("x is five!");
25+
println!("x は 5 です!");
2226
}
2327
```
2428

25-
If we changed the value of `x` to something else, this line would not print.
26-
More specifically, if the expression after the `if` evaluates to `true`, then
27-
the block is executed. If it’s `false`, then it is not.
29+
<!-- If we changed the value of `x` to something else, this line would not print. -->
30+
<!-- More specifically, if the expression after the `if` evaluates to `true`, then -->
31+
<!-- the block is executed. If it’s `false`, then it is not. -->
32+
仮に `x` を別の値へと変更すると、この行は表示されません。より正確に言うなら、
33+
`if` のあとにくる式が `true` に評価された場合に、ブロックが実行されます。
34+
`false` の場合、ブロックは実行されません。
2835

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

3139
```rust
3240
let x = 5;
3341

3442
if x == 5 {
35-
println!("x is five!");
43+
# // println!("x is five!");
44+
println!("x は 5 です!");
3645
} else {
37-
println!("x is not five :(");
46+
# // println!("x is not five :(");
47+
println!("x は 5 ではありません :(");
3848
}
3949
```
4050

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

4354
```rust
4455
let x = 5;
4556

4657
if x == 5 {
47-
println!("x is five!");
58+
# // println!("x is five!");
59+
println!("x は 5 です!");
4860
} else if x == 6 {
49-
println!("x is six!");
61+
# // println!("x is six!");
62+
println!("x は 6 です!");
5063
} else {
51-
println!("x is not five or six :(");
64+
# // println!("x is not five or six :(");
65+
println!("x は 5 でも 6 でもありません :(");
5266
}
5367
```
5468

55-
This is all pretty standard. However, you can also do this:
69+
<!-- This is all pretty standard. However, you can also do this: -->
70+
全くもって普通ですね。しかし、次のような使い方もできるのです:
5671

5772
```rust
5873
let x = 5;
@@ -64,14 +79,18 @@ let y = if x == 5 {
6479
}; // y: i32
6580
```
6681

67-
Which we can (and probably should) write like this:
82+
<!-- Which we can (and probably should) write like this: -->
83+
次のように書くこともできます(そして、大抵はこう書くべきです):
6884

6985
```rust
7086
let x = 5;
7187

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

75-
This works because `if` is an expression. The value of the expression is the
76-
value of the last expression in whichever branch was chosen. An `if` without an
77-
`else` always results in `()` as the value.
91+
<!-- This works because `if` is an expression. The value of the expression is the -->
92+
<!-- value of the last expression in whichever branch was chosen. An `if` without an -->
93+
<!-- `else` always results in `()` as the value. -->
94+
これが出来るのは `if` が式であるためです。その式の値は、選択された分岐中の最後の式の値となります。
95+
`else` のない `if` では、その値は常に `()` となります。
96+

0 commit comments

Comments
 (0)