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

Testing an Object

Previous pageReturn to chapter overviewNext page

Some objects understand messages that answer boolean true or false values. You can use these to test to see if an object is of a particular kind or in a particular state. Try these examples:

'this is not an integer' isInteger.

5 between: 0 and: 10.

$A isLowercase.

charlie respondsTo: #>=.


This last expression asks to see if charlie can understand a #>= message. We've already seen above that it can't so the false answer comes as no surprise.

Tip: many testing messages take the form #isXXX. You'll find that this helps to make code easy to read and also gives an indication that the message will answer a boolean value.