function Factorial( pnFact ) if ( pnFact > 1 ) return pnFact * Factorial( pnFact - 1 ) else return 1 endif endfuncAnd unless you are calculating thousands of them at a time, in which case even more processor time can be saved by precalculating a lookup array/table, the recursive form should have adequate performance. Actually I just tested this and the above function calculates 100,000 random factorials in 1.591 seconds and Vlad's non-recursive routine takes 2.407 seconds! The recursive method involves far fewer memory stores which probably accounts for this.
>LPARAMETERS nFactor > >local nRetVal >nRetVal = 0 > >DO CASE > CASE nFactor = 0 > nRetVal = 1 > return nRetVal > > CASE nFactor > 0 > nRetVal = nFactor * factorial(nFactor - 1) > RETURN nRetVal >ENDCASE >RETURN