user2522115 user2522115 - 1 year ago 160
Dart Question

For-in loops order in dart

if i use

loop in dart on some
, are the itterations guaranteed to be in the "correct order? e. g. Does the following code

List bars = getSomeListOfBars();

for(bar in bars){

in the exact same way as

List bars = getSomeListOfBars();

for(int i=0;i<bars.length;i++){

? I have not found
specific explanation anywhere, tthank you.

Answer Source

If you use for(x in y) with a collection that guarantees the iteration order, then for(x in y) is guaranteed to iterate in this order. If the collection itself doesn't guarantee the order, then of course for(x in y) doesn't as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download