A good place to start would be to have a look at "recursion" for factorial computation.