Fibonacci numbers in Logo

Example for versions UCBLogo 6.0

This example uses recursive definition of Fibonacci numbers. It defines two functions — fibonacci which calculates the value of Nth Fibonacci number and print_fibonacci which accumulates the numbers in a string and prints them.

to fibonacci :N
   ifelse :N < 3 [output 1] [output sum fibonacci :N - 1 fibonacci :N - 2]
end

to print_fibonacci :i :N
   make "str fibonacci :i
   make "i sum :i 1
   make "comma ",
   repeat :N - :i + 1 [make "str (word :str :comma fibonacci :i)
                      make "i sum :i 1]
   make "str word str ",...
   print str
end

print_fibonacci 1 16