czarnywdowiec
czarnywdowiec

Reputation: 21

OCaml issue Loop in Loop

I am writing program to count Bell numbers, it is my first big program in OCaml. I want to use loop While in the loop While, but there is syntax error. Please correct it. Thanks.

I'm using site http://try.ocamlpro.com/

let rec factorial n =   
if n < 2 
   then 1
else 
   n * factorial(n-1)

let rec newton n k =
factorial n / (factorial k * factorial (n-k))

let bell = [|1;1;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0|]

let i = ref 2
let k = ref 0
let x = ref 0
let z = ref 0
let s = ref 0

here you need to choose number u want to calc e.g. 4

let n = ref 4

if !n != 0 || !n != 1 then
    while !i <= !n do   
         while !k <= (!i-1) do
                x := newton (!i-1) !k;
                s := !s + (!x * bell.(!k));
                k := !k + 1 ;
                z := !k + 1
             done   
      s:=0;
      i:= !i + 1;
   done
else 
bell.(!n)<-1

Upvotes: 1

Views: 169

Answers (1)

Kakadu
Kakadu

Reputation: 2839

You can try to add ; after 1st done.

Upvotes: 1

Related Questions