目录

While…do循环

while...do表达式用于在指定的测试条件为真时执行迭代执行。

语法 (Syntax)

while test-expression do
   body-expression

首先评估测试表达式; 如果为true,则执行body-expression并再次计算测试表达式。 body-expression必须具有类型单位,即它不应返回任何值。 如果测试表达式为false,则迭代结束。

例子 (Example)

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
↑回到顶部↑
WIKI教程 @2018