I have a mutable.LinkedHashMap and try to remove item in a for-loop. However, if remove occurs, the for-loop also stops.
scala> val a = mutable.LinkedHashMap[Int, Int](1->1, 2->2, 3->3)
# when no remove occurs, for-loop works as expected
scala> for( (k,v) <- a ) { println(k); }
1
2
3
# following code doesn't work, only remove 1 and stop
scala> for( (k,v) <- a ) { println(k); a.remove(k) }
1
# following code work as expected
scala> a.keys.foreach{ k => println(k); a.remove(k) }
1
2
3
I am curious why remove stop for-loop.