@@ -182,14 +182,14 @@ <h1 class="title">ループ</h1>
182
182
183
183
<!-- 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. -->
184
184
185
- < p > なんらかの繰り返しを伴う処理に対して、Rust言語は3種類のアプローチ : < code > loop</ code > , < code > while</ code > , < code > for</ code > を提供します 。
186
- 各アプローチにはそれぞれの使い道があります 。</ p >
185
+ < p > 現在、Rustは、 なんらかの繰り返しを伴う処理に対して、3種類の手法 : < code > loop</ code > , < code > while</ code > , < code > for</ code > を提供しています 。
186
+ 各アプローチにはそれぞれの使い方があります 。</ p >
187
187
188
188
< h2 id ='loop ' class ='section-header '> < a href ='#loop '> loop</ a > </ h2 >
189
189
<!-- 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: -->
190
190
191
191
< p > Rustで使えるループのなかで最もシンプルな形式が、無限 < code > loop</ code > です。Rustのキーワード < code > loop</ code > によって、
192
- 何らかの終了状態に到達するまでずっとループし続ける手段を提供します 。Rustの無限 < code > loop</ code > はこのように :</ p >
192
+ 何らかの終了状態に到達するまで 延々とループし続ける手段を提供します 。Rustの無限 < code > loop</ code > は次の通りです :</ p >
193
193
194
194
< span class ='rusttest '> fn main() {
195
195
loop {
@@ -203,7 +203,7 @@ <h2 id='loop' class='section-header'><a href='#loop'>loop</a></h2>
203
203
< h2 id ='while ' class ='section-header '> < a href ='#while '> while</ a > </ h2 >
204
204
<!-- Rust also has a `while` loop. It looks like this: -->
205
205
206
- < p > Rustには < code > while</ code > ループもあります。このように :</ p >
206
+ < p > Rustには < code > while</ code > ループもあります。次の通りです :</ p >
207
207
208
208
< span class ='rusttest '> fn main() {
209
209
let mut x = 5; // mut x: i32
@@ -236,7 +236,7 @@ <h2 id='while' class='section-header'><a href='#while'>while</a></h2>
236
236
237
237
<!-- you need to loop. -->
238
238
239
- < p > 何回ループする必要があるか明らかではない状況で 、< code > while</ code > ループは正しい選択肢です 。</ p >
239
+ < p > 何回ループする必要があるか明らかではない状況では 、< code > while</ code > ループは正しい選択です 。</ p >
240
240
241
241
<!-- If you need an infinite loop, you may be tempted to write this: -->
242
242
@@ -249,7 +249,7 @@ <h2 id='while' class='section-header'><a href='#while'>while</a></h2>
249
249
250
250
<!-- However, `loop` is far better suited to handle this case: -->
251
251
252
- < p > しかし、こういった場合には < code > loop</ code > の方がずっと適しています 。</ p >
252
+ < p > しかし、 < code > loop</ code > は、 こういった場合に はるかに適しています 。</ p >
253
253
254
254
< span class ='rusttest '> fn main() {
255
255
loop {
@@ -268,7 +268,7 @@ <h2 id='while' class='section-header'><a href='#while'>while</a></h2>
268
268
269
269
< p > Rustの制御フロー解析では、必ずループすると知っていることから、これを < code > while true</ code > とは異なる構造として扱います。
270
270
一般に、コンパイラへ与える情報量が多いほど、安全性が高くより良いコード生成につながるため、
271
- 無限にループするつもりなら常に < code > loop</ code > を使うべきです。</ p >
271
+ 無限にループするつもりであれば、常に < code > loop</ code > を使うべきです。</ p >
272
272
273
273
< h2 id ='for ' class ='section-header '> < a href ='#for '> for</ a > </ h2 >
274
274
<!-- The `for` loop is used to loop a particular number of times. Rust’s `for` loops -->
@@ -277,8 +277,7 @@ <h2 id='for' class='section-header'><a href='#for'>for</a></h2>
277
277
278
278
<!-- loop doesn’t look like this “C-style” `for` loop: -->
279
279
280
- < p > 特定の回数だけループするときには < code > for</ code > ループを使います。しかし、Rustの < code > for</ code > ループは他のシステムプログラミング言語のそれとは少し異なる働きをします。
281
- Rustの < code > for</ code > ループは、次のような「Cスタイル」 < code > for</ code > ループとは似ていません:</ p >
280
+ < p > 特定の回数だけループするときには < code > for</ code > ループを使います。しかし、Rustの < code > for</ code > ループは他のシステムプログラミング言語のそれとは少し異なる働きをします。 Rustの < code > for</ code > ループは、次のような「Cスタイル」 < code > for</ code > ループとは似ていません:</ p >
282
281
283
282
< pre > < code class ="language-c "> for (x = 0; x < 10; x++) {
284
283
printf( "%d\n", x );
@@ -323,36 +322,33 @@ <h2 id='for' class='section-header'><a href='#for'>for</a></h2>
323
322
324
323
<!-- loop is over. -->
325
324
326
- < p > 式(expression)は< a href ="../std/iter/trait.IntoIterator.html "> < code > IntoIterator</ code > </ a > を用いて< a href ="iterators.html "> イテレータ</ a > へと変換可能なアイテムです。
327
- イテレータは要素の連なりを返します。それぞれの要素がループの1回の反復になります。
328
- その値は名前 < code > var</ code > に束縛されて、ループ本体にて有効になります。いったんループ本体を抜けると、
329
- 次の値がイテレータから取り出され、次のループ処理を行います。それ以上の値が存在しない時は、
330
- < code > for</ code > ループは終了します。</ p >
325
+ < p > 式(expression)は< a href ="../std/iter/trait.IntoIterator.html "> < code > IntoIterator</ code > </ a > を用いて< a href ="iterators.html "> イテレータ</ a > へと変換することができるアイテムです。
326
+ イテレータは一連の要素を返します。それぞれの要素がループの1回の反復になります。 その値は、ループ本体に有効な名前, < code > var</ code > に束縛されています。いったんループ本体を抜けると、次の値がイテレータから取り出され、次のループ処理を行います。それ以上の値が存在しない時は、< code > for</ code > ループは終了します。</ p >
331
327
332
328
<!-- In our example, `0..10` is an expression that takes a start and an end position, -->
333
329
334
330
<!-- and gives an iterator over those values. The upper bound is exclusive, though, -->
335
331
336
332
<!-- so our loop will print `0` through `9`, not `10`. -->
337
333
338
- < p > 例示では 、< code > 0..10</ code > が開始位置と終了位置をとる式であり 、同範囲の値を返すイテレータを与えます。
339
- 上界はその値自身を含まないため 、このループは < code > 0</ code > から < code > 9</ code > までを表示します。 < code > 10</ code > ではありません。</ p >
334
+ < p > この例では 、< code > 0..10</ code > が開始と終了位置をとる式であり 、同範囲の値を返すイテレータを与えます。
335
+ 上限はその値自身を含まないため 、このループは < code > 0</ code > から < code > 9</ code > までを表示します。 < code > 10</ code > ではありません。</ p >
340
336
341
337
<!-- Rust does not have the “C-style” `for` loop on purpose. Manually controlling -->
342
338
343
339
<!-- each element of the loop is complicated and error prone, even for experienced C -->
344
340
345
341
<!-- developers. -->
346
342
347
- < p > Rustでは意図的に「Cスタイル」 < code > for</ code > ループを持ちません。経験豊富なC開発者でさえ 、
348
- ループの各要素を手動制御することは複雑であり 、また間違いを犯しやすいのです。</ p >
343
+ < p > Rustでは意図的に「Cスタイル」 < code > for</ code > ループを持ちません。経験豊富なC言語の開発者でさえ 、
344
+ ループの各要素を手動で制御することは複雑であり 、また間違いを犯しやすいのです。</ p >
349
345
350
346
<!-- ### Enumerate -->
351
347
352
348
< h3 id ='列挙 ' class ='section-header '> < a href ='#列挙 '> 列挙</ a > </ h3 >
353
349
<!-- When you need to keep track of how many times you already looped, you can use the `.enumerate()` function. -->
354
350
355
- < p > ループ中で何回目の繰り返しかを知る必要があるなら 、 < code > .enumerate()</ code > 関数が使えます。</ p >
351
+ < p > ループの中で何回目の繰り返しかを把握する必要がある時 、 < code > .enumerate()</ code > 関数が使えます。</ p >
356
352
357
353
<!-- #### On ranges: -->
358
354
@@ -386,10 +382,13 @@ <h4 id='レンジを対象に' class='section-header'><a href='#レンジを対
386
382
< h4 id ='イテレータを対象に ' class ='section-header '> < a href ='#イテレータを対象に '> イテレータを対象に:</ a > </ h4 >
387
383
< span class ='rusttest '> fn main() {
388
384
let lines = "hello\nworld".lines();
385
+
389
386
for (linenumber, line) in lines.enumerate() {
390
387
println!("{}: {}", linenumber, line);
391
388
}
392
389
}</ span > < pre class ='rust rust-example-rendered '>
390
+ < span class ='kw '> let</ span > < span class ='ident '> lines</ span > < span class ='op '> =</ span > < span class ='string '> "hello\nworld"</ span > .< span class ='ident '> lines</ span > ();
391
+
393
392
< span class ='kw '> for</ span > (< span class ='ident '> linenumber</ span > , < span class ='ident '> line</ span > ) < span class ='kw '> in</ span > < span class ='ident '> lines</ span > .< span class ='ident '> enumerate</ span > () {
394
393
< span class ='macro '> println</ span > < span class ='macro '> !</ span > (< span class ='string '> "{}: {}"</ span > , < span class ='ident '> linenumber</ span > , < span class ='ident '> line</ span > );
395
394
}</ pre >
@@ -398,10 +397,8 @@ <h4 id='イテレータを対象に' class='section-header'><a href='#イテレ
398
397
399
398
< p > 出力:</ p >
400
399
401
- < pre > < code class ="language-text "> 0: Content of line one
402
- 1: Content of line two
403
- 2: Content of line three
404
- 3: Content of line four
400
+ < pre > < code class ="language-text "> 0: hello
401
+ 1: world
405
402
</ code > </ pre >
406
403
407
404
<!-- ## Ending iteration early -->
@@ -444,8 +441,8 @@ <h2 id='反復の早期終了' class='section-header'><a href='#反復の早期
444
441
445
442
<!-- modifying iteration: `break` and `continue`. -->
446
443
447
- < p > ループをいつ終了すべきか知るため、ここでは専用の < code > mut</ code > なboolean変数束縛 < code > done</ code > を用いました 。
448
- Rustには反復の変更を手伝う2つキーワード : < code > break</ code > と < code > continue</ code > があります。</ p >
444
+ < p > ループを終了する時を知るために、、専用の < code > mut</ code > であるboolean変数束縛, < code > done</ code > を使わなければなりませんでした 。
445
+ Rustには反復の変更を手伝けする2つのキーワード : < code > break</ code > と < code > continue</ code > があります。</ p >
449
446
450
447
<!-- In this case, we can write the loop in a better way with `break`: -->
451
448
@@ -474,8 +471,8 @@ <h2 id='反復の早期終了' class='section-header'><a href='#反復の早期
474
471
475
472
<!-- 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. -->
476
473
477
- < p > ここでは < code > loop</ code > による永久ループと < code > break</ code > による早期脱出を使っています 。
478
- 明示的な < code > return</ code > 文の発行でもループの早期終了になります 。</ p >
474
+ < p > ここでは < code > loop</ code > による永久ループと 早期にループを抜けるため < code > break</ code > を使っています 。
475
+ 明示的な < code > return</ code > 文の発行でもループを早期に終了します 。</ p >
479
476
480
477
<!-- `continue` is similar, but instead of ending the loop, goes to the next -->
481
478
@@ -506,7 +503,7 @@ <h2 id='ループラベル' class='section-header'><a href='#ループラベル'
506
503
507
504
<!-- other languages, by default a `break` or `continue` will apply to innermost -->
508
505
509
- <!-- loop. In a situation where you would like to a `break` or `continue` for one -->
506
+ <!-- loop. In a situation where you would like to `break` or `continue` for one -->
510
507
511
508
<!-- of the outer loops, you can use labels to specify which loop the `break` or -->
512
509
@@ -515,9 +512,8 @@ <h2 id='ループラベル' class='section-header'><a href='#ループラベル'
515
512
<!-- odd: -->
516
513
517
514
< p > 入れ子のループがあり、< code > break</ code > や < code > continue</ code > 文がどのループに対応するか指定する必要がある、
518
- そんな状況に出会うこともあるでしょう。大抵の他言語と同様に、 < code > break</ code > や < code > continue</ code > は最内ループに適用されるのがデフォルトです。
519
- 外側のループに < code > break</ code > や < code > continue</ code > を使いたいという状況では、 < code > break</ code > や < code > continue</ code > 文の適用先を指定するラベルを使えます。
520
- これは < code > x</ code > と < code > y</ code > 両方が奇数のときだけ表示を行います:</ p >
515
+ そのような状況に出会うかもしれません。大抵の他言語と同様に、 デフォルトで < code > break</ code > や < code > continue</ code > は最内ループに適用されます。
516
+ 外側のループに < code > break</ code > や < code > continue</ code > を使いたいという状況では、 < code > break</ code > や < code > continue</ code > 文の適用先を指定するラベルを使えます。これは < code > x</ code > と < code > y</ code > 両方がともに奇数のときだけ表示を行います:</ p >
521
517
522
518
< span class ='rusttest '> fn main() {
523
519
'outer: for x in 0..10 {
0 commit comments