Bug - Fixed Can't break from foreach for aggregates of depth 3

Ulti

Member
This works as expected, breaking after printing 'a -> apple' and hiding the 2nd two.
Code:
ash string[string] agg;agg['a']='apple';agg['b']='blue';agg['c']='carrot';foreach k,v, in agg{print(k+' -> '+v);break;}
Now, if I add an additional layer of depth, I'm unable to break from the loop and all 3 entries get printed, ignoring my break:
Code:
ash string[string,string] agg;agg['a']['apple']='';agg['b']['blue']='';agg['c']['carrot']='';foreach k,v in agg{print(k+' -> '+v);break;}
I've also tried:
Code:
ash string[string,string] agg;agg['a']['apple']='anthony';agg['b']['blue']='betty';agg['c']['carrot']='carl';foreach k,v,v2 in agg{print(k+' , '+v+' , '+v2);break;}
But still unable to break.
 

Ulti

Member
Figured it out:
Code:
foreach k in agg{
    foreach v,v2 in agg[k]
    {
        print(k+' , '+v+' , '+v2);
    }
    break;
}
 

heeheehee

Developer
Staff member
That still doesn't address the case where you might want to break out of some levels, but not all --- using Java syntax to demonstrate:
Code:
loop1:
for (ArrayList<Integer> v1 : agg) {
  loop2:
  for (Integer v2 : v1) {
    for (Integer v3 : arr[v2]) {
      if (condition(k2)) {
        break loop2;
      }
    }
  }
  // do other stuff
}
 
Top