![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Now you can redefine factorial
to
use a to:do:
message. All the multipliers are supplied by the
to:do:
method; there is no need to produce those multipliers
yourself:
Integer method definition instance factorial | result | result := 1. 1 to: self do: [:n | result := result * n]. ^ result Workspace Transcript show: 4 factorial printString Transcript 24