FUNCTION factorial (n AS Integer) AS Integer DIM f AS Integer, i AS Integer f = 1 FOR i = 2 TO n f = f*i NEXT i factorial = f END FUNCTION