[Newbies] Iterating backwards through a Matrix

Jan Teske jan.teske at student.hpi.uni-potsdam.de
Thu Dec 22 08:50:22 UTC 2011

I'm currently trying to develop a game with squeak. The game field is 
based on a Matrix in which all the game objects are placed.
To simulate gravity I need the possibility to iterate over the Matrix in 
a reversed order. For example if my Matrix looks like that:

     1 x x 2
     x 3 x x
     4 x x 5

I need to bring that into a Collection like {5. 4. 3. 2. 1} which allows 
me to perform iterations (select) over this reversed order. It would 
also be okay if the order was like {4. 5. 3. 1. 2} since I only need the 
elements in the lower rows to come before the elements in the upper rows.
I already tried 'myMatrix toArray reverse' but the toArray seems to mess 
up the whole order so that is not working. Maybe I could iterate through 
the Matrix on my own and build an Array out of that. But since I feel I 
might have overlookes something I wanted to ask for a better way first. 
Is there any?

Thanks in advance!

More information about the Beginners mailing list