Fsharp-while-loop

提供:Dev Guides
移動先:案内検索

F#-while..doループ

*while ... do* 式は、指定されたテスト条件が真である間に反復実行を実行するために使用されます。

構文

while test-expression do
   body-expression

テスト式が最初に評価されます。 trueの場合、body-expressionが実行され、テスト式が再度評価されます。 body-expressionはユニット型である必要があります。つまり、値を返しません。 テスト式が偽の場合、反復は終了します。

let mutable a = 10
while (a < 20) do
   printfn "value of a: %d" a
   a <- a + 1

あなたがプログラムをコンパイルして実行すると、次の出力が得られます-

value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19