Anonymous user
Category:Smalltalk: Difference between revisions
→Control Structures
Line 403:
Now, we can send this message to a boolean, and pass the code to be executed conditionally as a lambda block:
<lang smalltalk>(a > 0) ifYouAreTrueThenDo:[ 'positive' printCR ] ifNotThenDo:[ 'negative' printCR ]</lang>
actually, because these two return the value of the block
<lang smalltalk>( (a > 0) ifYouAreTrueThenDo:['positive'] ifNotThenDo:['negative'] ) printCR</lang>
Finally, by adding a self-returning "value" to the Object class, we can also write:
|