![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
As you would expect, Smalltalk also offers the whileFalse:
message. You can rewrite powerOfTwo
to test for n
equal to
zero, rather than n
not equal to zero:
Integer method definition instance powerOfTwo | n result | n := self. result := 1. [n = 0] whileFalse: [n := n - 1. result := 2 * result]. ^ result Workspace Transcript show: 4 powerOfTwo printString Transcript 16