Skip to content

Commit 86724e5

Browse files
authored
Merge pull request #160 from yosukehara/1.9/loops
4.6 - loop / ループ (1.9)
2 parents f11b208 + 97f56ac commit 86724e5

File tree

3 files changed

+32
-73
lines changed

3 files changed

+32
-73
lines changed

1.9/en/book/loops.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ Don't forget to add the parentheses around the range.
125125
#### On iterators:
126126

127127
```rust
128-
# let lines = "hello\nworld".lines();
128+
let lines = "hello\nworld".lines();
129+
129130
for (linenumber, line) in lines.enumerate() {
130131
println!("{}: {}", linenumber, line);
131132
}
@@ -134,10 +135,8 @@ for (linenumber, line) in lines.enumerate() {
134135
Outputs:
135136

136137
```text
137-
0: Content of line one
138-
1: Content of line two
139-
2: Content of line three
140-
3: Content of line four
138+
0: hello
139+
1: world
141140
```
142141

143142
## Ending iteration early
@@ -195,7 +194,7 @@ for x in 0..10 {
195194
You may also encounter situations where you have nested loops and need to
196195
specify which one your `break` or `continue` statement is for. Like most
197196
other languages, by default a `break` or `continue` will apply to innermost
198-
loop. In a situation where you would like to a `break` or `continue` for one
197+
loop. In a situation where you would like to `break` or `continue` for one
199198
of the outer loops, you can use labels to specify which loop the `break` or
200199
`continue` statement applies to. This will only print when both `x` and `y` are
201200
odd:

1.9/ja/book/loops.md

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<!-- % Loops -->
33

44
<!-- Rust currently provides three approaches to performing some kind of iterative activity. They are: `loop`, `while` and `for`. Each approach has its own set of uses. -->
5-
なんらかの繰り返しを伴う処理に対して、Rust言語は3種類のアプローチ: `loop`, `while`, `for` を提供します
6-
各アプローチにはそれぞれの使い道があります
5+
現在、Rustは、なんらかの繰り返しを伴う処理に対して、3種類の手法: `loop`, `while`, `for` を提供しています
6+
各アプローチにはそれぞれの使い方があります
77

88
## loop
99

1010
<!-- The infinite `loop` is the simplest form of loop available in Rust. Using the keyword `loop`, Rust provides a way to loop indefinitely until some terminating statement is reached. Rust's infinite `loop`s look like this: -->
1111
Rustで使えるループのなかで最もシンプルな形式が、無限 `loop` です。Rustのキーワード `loop` によって、
12-
何らかの終了状態に到達するまでずっとループし続ける手段を提供します。Rustの無限 `loop` はこのように:
12+
何らかの終了状態に到達するまで 延々とループし続ける手段を提供します。Rustの無限 `loop` は次の通りです:
1313

1414
```rust,ignore
1515
loop {
@@ -20,7 +20,7 @@ loop {
2020
## while
2121

2222
<!-- Rust also has a `while` loop. It looks like this: -->
23-
Rustには `while` ループもあります。このように:
23+
Rustには `while` ループもあります。次の通りです:
2424

2525
```rust
2626
let mut x = 5; // mut x: i32
@@ -39,7 +39,7 @@ while !done {
3939

4040
<!-- `while` loops are the correct choice when you’re not sure how many times -->
4141
<!-- you need to loop. -->
42-
何回ループする必要があるか明らかではない状況で`while` ループは正しい選択肢です
42+
何回ループする必要があるか明らかではない状況では`while` ループは正しい選択です
4343

4444
<!-- If you need an infinite loop, you may be tempted to write this: -->
4545
無限ループの必要があるとき、次のように書きたくなるかもしれません:
@@ -49,7 +49,7 @@ while true {
4949
```
5050

5151
<!-- However, `loop` is far better suited to handle this case: -->
52-
しかし、こういった場合には `loop` の方がずっと適しています
52+
しかし、 `loop`は、 こういった場合に はるかに適しています
5353

5454
```rust,ignore
5555
loop {
@@ -62,7 +62,7 @@ loop {
6262
<!-- infinitely. -->
6363
Rustの制御フロー解析では、必ずループすると知っていることから、これを `while true` とは異なる構造として扱います。
6464
一般に、コンパイラへ与える情報量が多いほど、安全性が高くより良いコード生成につながるため、
65-
無限にループするつもりなら常に `loop` を使うべきです。
65+
無限にループするつもりであれば、常に `loop` を使うべきです。
6666

6767

6868
## for
@@ -71,8 +71,7 @@ Rustの制御フロー解析では、必ずループすると知っているこ
7171
<!-- work a bit differently than in other systems languages, however. Rust’s `for` -->
7272
<!-- loop doesn’t look like this “C-style” `for` loop: -->
7373

74-
特定の回数だけループするときには `for` ループを使います。しかし、Rustの `for` ループは他のシステムプログラミング言語のそれとは少し異なる働きをします。
75-
Rustの `for` ループは、次のような「Cスタイル」 `for` ループとは似ていません:
74+
特定の回数だけループするときには `for` ループを使います。しかし、Rustの `for` ループは他のシステムプログラミング言語のそれとは少し異なる働きをします。 Rustの `for` ループは、次のような「Cスタイル」 `for` ループとは似ていません:
7675

7776
```c
7877
for (x = 0; x < 10; x++) {
@@ -104,32 +103,29 @@ for var in expression {
104103
<!-- valid for the loop body. Once the body is over, the next value is fetched from -->
105104
<!-- the iterator, and we loop another time. When there are no more values, the `for` -->
106105
<!-- loop is over. -->
107-
式(expression)は[`IntoIterator`]を用いて[イテレータ][iterator]へと変換可能なアイテムです。
108-
イテレータは要素の連なりを返します。それぞれの要素がループの1回の反復になります。
109-
その値は名前 `var` に束縛されて、ループ本体にて有効になります。いったんループ本体を抜けると、
110-
次の値がイテレータから取り出され、次のループ処理を行います。それ以上の値が存在しない時は、
111-
`for` ループは終了します。
106+
式(expression)は[`IntoIterator`]を用いて[イテレータ][iterator]へと変換することができるアイテムです。
107+
イテレータは一連の要素を返します。それぞれの要素がループの1回の反復になります。 その値は、ループ本体に有効な名前, `var` に束縛されています。いったんループ本体を抜けると、次の値がイテレータから取り出され、次のループ処理を行います。それ以上の値が存在しない時は、`for` ループは終了します。
112108

113109
[iterator]: iterators.html
114110
[`IntoIterator`]: ../std/iter/trait.IntoIterator.html
115111

116112
<!-- In our example, `0..10` is an expression that takes a start and an end position, -->
117113
<!-- and gives an iterator over those values. The upper bound is exclusive, though, -->
118114
<!-- so our loop will print `0` through `9`, not `10`. -->
119-
例示では`0..10` が開始位置と終了位置をとる式であり、同範囲の値を返すイテレータを与えます。
120-
上界はその値自身を含まないため、このループは `0` から `9` までを表示します。 `10` ではありません。
115+
この例では`0..10` が開始と終了位置をとる式であり、同範囲の値を返すイテレータを与えます。
116+
上限はその値自身を含まないため、このループは `0` から `9` までを表示します。 `10` ではありません。
121117

122118
<!-- Rust does not have the “C-style” `for` loop on purpose. Manually controlling -->
123119
<!-- each element of the loop is complicated and error prone, even for experienced C -->
124120
<!-- developers. -->
125-
Rustでは意図的に「Cスタイル」 `for` ループを持ちません。経験豊富なC開発者でさえ
126-
ループの各要素を手動制御することは複雑であり、また間違いを犯しやすいのです。
121+
Rustでは意図的に「Cスタイル」 `for` ループを持ちません。経験豊富なC言語の開発者でさえ
122+
ループの各要素を手動で制御することは複雑であり、また間違いを犯しやすいのです。
127123

128124
<!-- ### Enumerate -->
129125
### 列挙
130126

131127
<!-- When you need to keep track of how many times you already looped, you can use the `.enumerate()` function. -->
132-
ループ中で何回目の繰り返しかを知る必要があるなら`.enumerate()` 関数が使えます。
128+
ループの中で何回目の繰り返しかを把握する必要がある時`.enumerate()` 関数が使えます。
133129

134130
<!-- #### On ranges: -->
135131
#### レンジを対象に:
@@ -158,7 +154,8 @@ i = 4 and j = 9
158154
#### イテレータを対象に:
159155

160156
```rust
161-
# let lines = "hello\nworld".lines();
157+
let lines = "hello\nworld".lines();
158+
162159
for (linenumber, line) in lines.enumerate() {
163160
println!("{}: {}", linenumber, line);
164161
}
@@ -168,10 +165,8 @@ for (linenumber, line) in lines.enumerate() {
168165
出力:
169166

170167
```text
171-
0: Content of line one
172-
1: Content of line two
173-
2: Content of line three
174-
3: Content of line four
168+
0: hello
169+
1: world
175170
```
176171

177172
<!-- ## Ending iteration early -->
@@ -198,8 +193,9 @@ while !done {
198193
<!-- We had to keep a dedicated `mut` boolean variable binding, `done`, to know -->
199194
<!-- when we should exit out of the loop. Rust has two keywords to help us with -->
200195
<!-- modifying iteration: `break` and `continue`. -->
201-
ループをいつ終了すべきか知るため、ここでは専用の `mut` なboolean変数束縛 `done` を用いました。
202-
Rustには反復の変更を手伝う2つキーワード: `break``continue` があります。
196+
197+
ループを終了する時を知るために、、専用の `mut`であるboolean変数束縛, `done` を使わなければなりませんでした。
198+
Rustには反復の変更を手伝けする2つのキーワード: `break``continue` があります。
203199

204200
<!-- In this case, we can write the loop in a better way with `break`: -->
205201
この例では、 `break` を使ってループを記述した方が良いでしょう:
@@ -217,8 +213,8 @@ loop {
217213
```
218214

219215
<!-- We now loop forever with `loop` and use `break` to break out early. Issuing an explicit `return` statement will also serve to terminate the loop early. -->
220-
ここでは `loop` による永久ループと `break` による早期脱出を使っています
221-
明示的な `return` 文の発行でもループの早期終了になります
216+
ここでは `loop` による永久ループと 早期にループを抜けるため `break` を使っています
217+
明示的な `return` 文の発行でもループを早期に終了します
222218

223219
<!-- `continue` is similar, but instead of ending the loop, goes to the next -->
224220
<!-- iteration. This will only print the odd numbers: -->
@@ -239,14 +235,13 @@ for x in 0..10 {
239235
<!-- You may also encounter situations where you have nested loops and need to -->
240236
<!-- specify which one your `break` or `continue` statement is for. Like most -->
241237
<!-- other languages, by default a `break` or `continue` will apply to innermost -->
242-
<!-- loop. In a situation where you would like to a `break` or `continue` for one -->
238+
<!-- loop. In a situation where you would like to `break` or `continue` for one -->
243239
<!-- of the outer loops, you can use labels to specify which loop the `break` or -->
244240
<!-- `continue` statement applies to. This will only print when both `x` and `y` are -->
245241
<!-- odd: -->
246242
入れ子のループがあり、`break``continue` 文がどのループに対応するか指定する必要がある、
247-
そんな状況に出会うこともあるでしょう。大抵の他言語と同様に、 `break``continue` は最内ループに適用されるのがデフォルトです。
248-
外側のループに `break``continue` を使いたいという状況では、 `break``continue` 文の適用先を指定するラベルを使えます。
249-
これは `x``y` 両方が奇数のときだけ表示を行います:
243+
そのような状況に出会うかもしれません。大抵の他言語と同様に、 デフォルトで `break``continue` は最内ループに適用されます。
244+
外側のループに `break``continue` を使いたいという状況では、 `break``continue` 文の適用先を指定するラベルを使えます。これは `x``y` 両方がともに奇数のときだけ表示を行います:
250245

251246
```rust
252247
'outer: for x in 0..10 {

diff-1.6.0..1.9.0/src/doc/book/loops.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)