![]() |
![]() |
![]() |
![]() |
![]() |
|
You can iterate over the elements in an OrderedCollection instance by
using a do: message exactly like the do: message used to
iterate over the elements in arrays:
Workspace (OrderedCollection new addFirst: 570; addFirst: 720; addFirst: 640; addFirst: 720; yourself) do: [:element | Transcript show: element printString; space] Transcript 720 640 720 570
An OrderedCollection instance, acting as a receiver, handles blocks
just as an Array instance would: both evaluate the block as many
times as there are elements in the ordered collection. Each such
evaluation is done with a different ordered-collection element assigned to
the parameter. Thus, the do: expression performs
ordered-collection iteration.