#!/bin/bash
#### Compute factorial (by looping)

factorial()
{
  result=1
  for i in `seq 1 $1`           # Sequence from 1 to n
  do
        let result=$result*$i
  done
  echo $result                  # Return the result.
}

echo "#### Factorials ####"
echo "(Enter zero to stop.)"
echo -n "Enter the first number:	"
read n

while [ $n -ge 1 ]
do
        answer=`factorial $n`
        echo "The factorial of $n is:  $answer"

        echo -n "Next number:	 "
        read n
done

echo "# Thanks for using my facloop script.#"
echo ""
