cwtests/cw05/sqr.fun
author Christian Urban <christian.urban@kcl.ac.uk>
Fri, 18 Oct 2024 05:45:14 +0100
changeset 969 0dfa2923a7c6
parent 856 23273e3a120f
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
856
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     1
val Max : Int = 10;
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     2
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     3
def sqr(x: Int) : Int = x * x;
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
def all(n: Int) : Void = {
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     6
  if n <= Max
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
  then { print_int(sqr(n)) ; new_line(); all(n + 1) }
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     8
  else skip()
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     9
};
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    10
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    11
all(0)
23273e3a120f updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
    12