# Fibonacci numbers in REXX

Example for versions
REXX

This example uses iterative definition of Fibonacci numbers.

In REXX, an uninitialized variable has its name in uppercase as its value; e.g. numbers = ‘NUMBERS’

Line 4: Arrays are called “stem variables”. The root of a stem ends with a period. Elements of a stem are named by adding a value to the stem; e.g. fib.1, fib.first, etc. Additional dimensions may be used by adding another period and value; e.g., fib.1.3; To initialize all possible stem instances, assign a value to the stem name; e.g., fib. = 0 or fib. = ”

```
1 #!/usr/bin/rexx
2 /* Calculate Fibonacci using an associative array */
3
4 fib. = ''
5 fib.1 = 1
6 fib.2 = 1
7 numbers = ''
8
9 do f = 3 to 16
10 e = f - 1; d = f - 2
11 fib.f = fib.e + fib.d
12 end
13
14 do n = 1 to 16
15 numbers = numbers fib.n','
16 fib.f = fib.e + fib.d
17 end
18
19 say numbers"..."
20 exit
```

## Comments

]]>blog comments powered by Disqus

]]>