progs/fun2/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 22 Jan 2021 10:39:04 +0000
changeset 822 6b06aeb192ea
parent 820 7fd1f611c21d
child 854 ce4a7bab6bd8
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
820
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
val Max : Int = 10;
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def sqr(x: Int) : Int = x * x;
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
def all(n: Int) : Void = {
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  if n <= Max
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  then print_int(sqr(n)) ; all(n + 1)
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
  else skip()
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
};
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
all(0)
7fd1f611c21d updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12