Is it possible to write a script that calculates the nth Fibonacci number - iteratively. I did it recursive (showed below) but could find solution iteratively. Please help.
#!/bin/bash
fib()
{
if [ $1 -le 0 ]
then
echo 0
return 0
fi
if [ $1 -le 2 ]
then
echo 1
else
a=$(fib $[$1-1])
b=$(fib $[$1-2])
echo $(($a+$b))
fi
}