# Factorial in Logo

Example for versions
UCBLogo 6.0

This example uses recursive factorial definition. It defines two functions — `factorial`

which calculates N! and `print_factorial`

which loops through numbers from i to N and outputs their factorials.

```
to factorial :N
ifelse :N = 0 [output 1] [output :N * factorial :N - 1]
end
to print_factorial :i :N
repeat :N - :i + 1 [(print :i [! =] factorial :i)
make "i sum :i 1]
end
print_factorial 0 16
```

## Comments

]]>blog comments powered by Disqus

]]>