我是F#的新手,但是当我使用详细语法时 在另一个中放一个for循环, 它不会编译:
#light "off"
let Multiple9x9 () =
for i in 1 .. 9 do
printf "\n";
for j in 1 .. 9 do
let k = i * j;
printf "%d x %d = %2d " i j k ;
done;;
done;;
Multiple9x9 ();;
printf "\n" ;;
我知道它适用于#light“on”:
let Multiple9x9 () =
for i in 1 .. 9 do
printf "\n"
for j in 1 .. 9 do
let k = i * j
printf "%d x %d = %2d " i j k
Multiple9x9 ()
printf "\n"
答案 0 :(得分:6)
如果您要使用详细语法,则在每次in
绑定后需要let
。此外,在内循环中;;
之后您不需要done
:它会使外循环不完整(切断外部done
)。
以下是更正后的代码:
let Multiple9x9 () =
for i in 1 .. 9 do
printf "\n";
for j in 1 .. 9 do
let k = i * j in
printf "%d x %d = %2d " i j k;
done;
done;;
Multiple9x9 ();;
printf "\n" ;;