An example of a recursive procedure is

1proc factorial {number} {
2  if {$number <= 1} {
3    return 1
4  }
5  return [expr $number * [factorial [expr $number - 1]]]
6}
7puts [factorial 5]
8puts [factorial 10]

Result:

1120
23628800

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading