progs/fun2/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Sat, 09 Oct 2021 12:29:15 +0100
changeset 843 97b622202547
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