Navigation:  Tutorials > Beginners Guide to Smalltalk > Control Flow >

More Complicated Boolean Expressions

Previous pageReturn to chapter overviewNext page

So far we have only used boolean expressions containing a single condition. Sometimes it is necessary to use a combination of conditions that make up a more complex expression. Try displaying the results of the following to see if you're working too hard:

Time now hours>22 or: [Time now hours<6].


If the current time is between 10 p.m. and 6 a.m., this expression will answer true. By now you should be able to see what's going on here. The #or: message is being received by a boolean value (the result of Time now hours>22) and being passed another condition in a block of code which needs to be evaluated if the receiver is false. The result of the #or: message is that of the combined condition.

An #and: message is also available:

charlie radius: 40.

[simon radius > charlie radius and: [simon radius > teresa radius]]

       whileTrue: [ simon shrinkBy: 10 ].


This shrinks simon to be the same size as the larger of the other two shapes. Notice that, in this situation, the #and: expression has being enclosed in another block so that it can be repeatedly evaluated by #whileTrue: until the required size is reached.