# Factorial in Icon

Example for versions
iconc 9.4

This example uses recursive factorial definition. `0 to 16`

is a generator which returns all integers between 0 and 16, inclusive. `every ... do`

allows to fetch every result returned by the generator and process it (calculate factorial and perform `write`

).

```
procedure factorial (n)
if n = 0 then
return 1
else if n > 0 then
return n * factorial (n - 1)
end
procedure main ()
local i
every i := 0 to 16 do
write (i, "! = ", factorial (i))
end
```

## Comments

]]>blog comments powered by Disqus

]]>