progs/fun2/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 10 Oct 2022 15:15:15 +0100
changeset 888 fc812b8f120f
parent 854 ce4a7bab6bd8
permissions -rw-r--r--
texupdate
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
854
ce4a7bab6bd8 testcases
Christian Urban <christian.urban@kcl.ac.uk>
parents: 820
diff changeset
     7
  then { print_int(sqr(n)) ; new_line(); all(n + 1) }
820
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