Category:Smalltalk: Difference between revisions

Line 461:
 
=== Control Structures ===
As mentioned above, these are defined as messages and their implementation is found in the corresponding receiver's classesclass. For illustration, here is how conditional execution ('if-then-else') is implemented in Smalltalk. There are two boolean objects named "true" and "false", which are singletons of corresponding classes named "True" and "False" (both inherit from Boolean, which inherits from Object). It is essential, that these are singletons, and that typical relational operators like "<", ">" etc. return one of those two.
<br>Then, in the True class, define:
<lang smalltalk>ifYouAreTrueThenDo: arg1 ifNotThenDo: arg2
Anonymous user