2

我是 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"
4

1 回答 1

6

如果您要in在每次let绑定后使用所需的详细语法。此外,内循环中不需要;;after 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" ;;
于 2012-08-31T16:54:44.460 回答