Factorial in Icon

Example for versions iconc 9.4

This example uses iterative factorial definition written in short form. every j *= 1 to i multiplies j by all values returned by the generator 1 to i. The expression in braces calculates factorial by multiplying j by all values between 1 and i and returns it. The outer expression calculates and prints factorials of all numbers returned by the generator 0 to 16.

procedure main ()
   local i, j
   every write (i := 0 to 16, "! = ", { j := 1; every j *:= 1 to i; j })