The new version works for two reasons:
self
is 0
, the recursivePowerOfTwo
method
answers 1
.
self
is not 0
, the
recursivePowerOfTwo
method
first computes the result of the expression self - 1
. Next,
the recursivePowerOfTwo
method sends the recursivePowerOfTwo
message
to that result to compute the power of 2 for a number that is 1 less
than the value of self
. Then, the recursivePowerOfTwo
method may send another recursivePowerOfTwo
message to ask itself
to compute the power of 2 for a number that is 2 less than the original
value of self
, and so on, until the recursivePowerOfTwo
method needs to deal with only 0
.