home *** CD-ROM | disk | FTP | other *** search
/ Practical Programming in Tcl & Tk (4th Edition) / TCLBOOK4.BIN / pc / exsource.old / 1_13.tcl < prev    next >
Text File  |  2003-04-15  |  217b  |  18 lines

  1. #
  2. # Example 1-13
  3. # A while loop to compute factorial.
  4. #
  5.  
  6. proc Factorial {x} {
  7.     set i 1; set product 1
  8.     while {$i <= $x} {
  9.         set product [expr {$product * $i}]
  10.         incr i
  11.     }
  12.     return $product
  13. }
  14. Factorial 10
  15. #=> 3628800
  16.  
  17.  
  18.