Edit | Rename | Changes | History | Upload | Download | Back to Top |
true ifTrue: ['this is the answer'] ifFalse: ['not this'] false ifTrue: ['not this one'] ifFalse: ['but this'] true ifTrue: ['return me'] false ifFalse: ['return me']However, the following do not return strings. You should think of them as not returning anything. In fact, they do return something, because ever method returns something. Experiment and see what they return.
true ifFalse: ['not returned'] false ifTrue: ['not returned']You can look in class True and class False to see how they are implemented.
Note that the expression
t := x < y ifTrue: [^x] ifFalse: [^y]will return from the method it was defined in, and in some sense has no value. It never assigns a value to t. The expression
x < y ifTrue: [t:=x] ifFalse: [t:=y]does assign a value to t. Its value will be the same as the value assigned to t. It is exactly the same as the expression
t := x < y ifTrue: [x] ifFalse: [y]Smalltalk does not have a case statement. It does not need one. It is easy to add one if you want to, but you will decide later it was a mistake.
Edit | Rename | Changes | History | Upload | Download | Back to Top |