Next: Debugging, Previous: Code blocks (I), Up: Tutorial
In the last chapter, we looked at how code blocks could be used to build conditional expressions, and how you could iterate across all entries in a collection.32 We built our own code blocks, and handed them off for use by system objects. But there is nothing magic about invoking code blocks; your own code will often need to do so. This chapter will shows some examples of loop construction in Smalltalk, and then demonstrate how you invoke code blocks for yourself.
The
do:
message is understood by most types
of Smalltalk collections. It works for the
Dictionary class, as well as sets, arrays, strings,
intervals, linked lists, bags, and streams. The
keysDo:
message, for example, works only with dictionaries.