view graal/com.oracle.truffle.sl.test/tests/Fibonacci.sl @ 21132:fc6fd02ecf95

Merge with f6f3f44a183051ae5ee581be7c8c6c8cbbc0d5fe
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Sun, 26 Apr 2015 20:50:30 -0700
parents ff3136ecb5a7
children
line wrap: on
line source

function fib(num) { 
  if (num < 1) {return 0;}
  n1 = 0;
  n2 = 1;
  i = 1;
  while (i < num) {
    next = n2 + n1;
    n1 = n2;
    n2 = next;
    i = i + 1;
  }
  return n2;
}

function main() {  
  i = 1;
  while (i <= 10) {
    println(i + ": " + fib(i));
    i = i + 1;
  }
}