Iterate collection back in Pharo Smalltalk

I am using Pharo and I am trying to iterate over an OrderedCollection , but starting from the end.

For example:

 | c | c := OrderedCollection new. c add: (1). c add: (2). c add: (3). c do: [ :each | Transcript show: each ; cr ] 

The result is 1 2 3 , but I want 3 2 1 .

Is it possible, or do I need to use a different kind of collection?

+7
smalltalk squeak pharo
source share
1 answer

To iterate the OrderedCollection in reverse, you can use the reverseDo: method reverseDo: for example:

 c reverseDo: [ :each | Transcript show: each; cr ]. 
+13
source share

All Articles