**10.4 For-Loops For-comprehensions resemble for-loops in imperative languages, except that they produce a list of results. Sometimes, a list of results is not needed but we would still like the flexibility of generators and filters in iterations over lists. This is made possible by a variant of the for-comprehension syntax, which expresses for-loops: for 内包表現は命令型言語の for ループに似ていますが、結果のリストを生成します。時には、結果のリストは必要とはしないがリストに対するジェネレータとフィルタの柔軟性が欲しい場合があります。これは for 内包表現の変種で可能で for ループを表現します。 for ( s ) e This construct is the same as the standard for-comprehension syntax except that the keyword yield is missing. The for-loop is executed by executing the expression e for each element generated from the sequence of generators and filters s . この構文は標準的な for 内包表現構文と同じですがキーワード yield がありません。for ループは、ジェネレータとフィルタの列 s から生成される各要素に対して式 e を事項する事で実行されます。 As an example, the following expression prints out all elements of a matrix represented as a list of lists: 例として、下記の式はリストのリストとして表現される行列の全要素を印刷します。 for (xs <- xss) { for (x <- xs) print(x + "\t") println() } The translation of for-loops to higher-order methods of class List is similar to the translation of for-comprehensions, but is simpler. Where for-comprehensions translate to map and flatMap, for-loops translate in each case to foreach. for ループのクラス List の高階メソッドへの翻訳は for 内包表現の翻訳と似ていますがより単純です。for 内包表現で map と flatMap へと翻訳するところで、for ループはそれらを foreach へと翻訳します。 ---- #comment
下から選んでください: