[Newbies] collection enumeration

Ralph Johnson johnson at cs.uiuc.edu
Wed Aug 23 22:35:49 UTC 2006


I usually use option C.

> (a) ---- à la C
>
> (1 to: collection size) do: [:index |
>                                                 html render: 'Victime ', index printString.
>                                                 html render: collection at: index]

This can be fast if collection is an array and if you say "1 to:
collection do: [:index | ..."
instead of creating an interval.  The compiler cheats for to:do: on a
SmallInteger and doesn't create the block.  But I would only use this
if the profiler showed it was a real improvement.  Almost always I
would use option C.

-Ralph


More information about the Beginners mailing list