loop..over..<iterable> returns objects in reverse order

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

loop..over..<iterable> returns objects in reverse order

tegatai
This post was updated on .
Just checking to see if anyone else has experienced this issue.  

When using loop..over a Java Object that implements java.lang.Iterable to process a collection of objects, the objects are returned in reverse order i.e. the last object is returned first and the first object is returned last.

Here are simple examples for NetRexx, JavaScript & Java.

In NetRexx 3.02 (using jsr-223 NetRexx ScriptEngine over Java 7):

aThing=Thing
loop aThing over things
   say aThing.getThingId()
end

Produces the following output:
ZZZ
XXX
YYY
...
...
CCC
BBB
AAA

In JavaScript (using Rhino ScriptEngine over Java 7):

for (var thing in Iterable(things)){
   print(thing.getThingId()+"\n");
}

Produces the following output:
AAA
BBB
CCC
...
...
XXX
YYY
ZZZ

In Java 7:

for (Thing thing : things){
   System.out.println(thing.getThingId());
}

Produces the following output:
AAA
BBB
CCC
...
...
XXX
YYY
ZZZ