4
4
<!-- Rust’s take on `if` is not particularly complex, but it’s much more like the -->
5
5
<!-- `if` you’ll find in a dynamically typed language than in a more traditional -->
6
6
<!-- systems language. So let’s talk about it, to make sure you grasp the nuances. -->
7
- Rustにおける ` if ` の扱いはさほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれに比べて、
8
- 動的型付け言語でみられる ` if ` にずっと近いものになっています。そのニュアンスをしっかり理解できるよう、
9
- さっそく説明していきましょう。
7
+ Rustにおける ` if ` の扱いは さほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれと比べて、
8
+ 動的型付け言語の ` if ` により近いものになっています。そのニュアンスをしっかり理解できるように、説明しましょう。
10
9
11
- <!-- `if` is a specific form of a more general concept, the ‘branch’. The name comes -->
10
+ <!-- `if` is a specific form of a more general concept, the ‘branch’. whose name comes -->
12
11
<!-- from a branch in a tree: a decision point, where depending on a choice, -->
13
12
<!-- multiple paths can be taken. -->
14
- ` if ` は一般化されたコンセプト 、「分岐(branch)」の特別な形式です。この名前は木の枝 (branch)を由来とし :
15
- 取りうる複数のパスから、選択の決定を行うポイントを表します 。
13
+ ` if ` は より一般的なコンセプトの一つである 、「分岐(branch)」の具体的な形です。この名称は、木の枝 (branch)に由来します :
14
+ 決定点はひとつの選択に依存し、複数のパスを取ることができます 。
16
15
17
16
<!-- In the case of `if`, there is one choice that leads down two paths: -->
18
- ` if ` の場合は、続く2つのパスから1つを選択します 。
17
+ ` if ` の場合は、二つのパスを導く ひとつの選択があります 。
19
18
20
19
``` rust
21
20
let x = 5 ;
@@ -29,12 +28,11 @@ if x == 5 {
29
28
<!-- If we changed the value of `x` to something else, this line would not print. -->
30
29
<!-- More specifically, if the expression after the `if` evaluates to `true`, then -->
31
30
<!-- the block is executed. If it’s `false`, then it is not. -->
32
- 仮に ` x ` を別の値へと変更すると、この行は表示されません。より正確に言うなら、
33
- ` if ` のあとにくる式が ` true ` に評価された場合に、ブロックが実行されます。
34
- ` false ` の場合、ブロックは実行されません。
31
+ もし、` x ` を別の値に変更すると、この行は出力されません。よりわかりやすく説明すると、
32
+ ` if ` のあとにくる式が ` true ` に評価された場合、そのブロックが実行されます。また、` false ` の場合は、それは実行されません。
35
33
36
34
<!-- If you want something to happen in the `false` case, use an `else`: -->
37
- ` false ` の場合にも何かをしたいなら 、 ` else ` を使います:
35
+ ` false ` の場合にも何かをしたい時は 、 ` else ` を使います:
38
36
39
37
``` rust
40
38
let x = 5 ;
@@ -49,7 +47,7 @@ if x == 5 {
49
47
```
50
48
51
49
<!-- If there is more than one case, use an `else if`: -->
52
- 場合分けが複数あるときは 、 ` else if ` を使います:
50
+ 複数の条件がある時は 、 ` else if ` を使います:
53
51
54
52
``` rust
55
53
let x = 5 ;
@@ -67,7 +65,7 @@ if x == 5 {
67
65
```
68
66
69
67
<!-- This is all pretty standard. However, you can also do this: -->
70
- 全くもって普通ですね。しかし、次のような使い方もできるのです :
68
+ これは当然なことですが、次のように書くこともできます :
71
69
72
70
``` rust
73
71
let x = 5 ;
@@ -80,7 +78,7 @@ let y = if x == 5 {
80
78
```
81
79
82
80
<!-- Which we can (and probably should) write like this: -->
83
- 次のように書くこともできます(そして、大抵はこう書くべきです) :
81
+ また、次のように書くのがほとんどの場合良いでしょう :
84
82
85
83
``` rust
86
84
let x = 5 ;
@@ -91,6 +89,5 @@ let y = if x == 5 { 10 } else { 15 }; // y: i32
91
89
<!-- This works because `if` is an expression. The value of the expression is the -->
92
90
<!-- value of the last expression in whichever branch was chosen. An `if` without an -->
93
91
<!-- `else` always results in `()` as the value. -->
94
- これが出来るのは ` if ` が式であるためです。その式の値は、選択された分岐中の最後の式の値となります。
95
- ` else ` のない ` if ` では、その値は常に ` () ` となります。
96
-
92
+ これが出来るのは ` if ` が式だからです。その式の値は、選択された条件の最後の式の値です。
93
+ ` else ` のない ` if ` では、その値は常に ` () ` になります。
0 commit comments