Factorial in Tcl

Example for versions ActiveTcl 8.5, JTcl 2.1.0, Tcl 8.4, Tcl 8.5.7

This example uses iterative factorial definition. In Tcl 8.4 values of factorials starting with 13! are calculated incorrectly due to overflow. In later versions and other implementations all values are correct.

set fact 1
for {set i 0} {$i <= 16} {incr i} {
    puts "$i! = $fact"
    set fact [expr {$fact * ($i + 1)}]
}