Difference between revisions of "ForEach"
Jump to navigation
Jump to search
Added scruggsy's clarifications on iterating arrays
imported>QQuix (New page - Text from OBSE doc) |
imported>QQuix (Added scruggsy's clarifications on iterating arrays) |
||
Line 26: | Line 26: | ||
===Notes=== | ===Notes=== | ||
====For arrays==== | |||
It's fine to modify the array while iterating over it (removal, insertion, etc). | |||
This includes removing the element associated with the current value of the iterator, considering: | |||
:*If you remove the current entry from a Map or StringMap the iteration will exit. | |||
:*If you remove the current entry from an Array, when you remove the nth entry, iteration will continue with entry n+1. | |||
If you insert an element from within the foreach loop, that element will be included in the iteration if its key is greater than that of the current key when the element is inserted. e.g.: | |||
let someStringMap := ar_map "whatever"::something "stuff"::somethingElse "anotherElement"::moreStuff | |||
foreach iter <- someStringMap | |||
if eval iter->key == "stuff" | |||
someStringMap->things := chickens | |||
someStringMap->blah := etc | |||
endif | |||
loop | |||
After the insertion the next element in the iterator will be "things". The iterator will never get to "blah". | |||
===See Also=== | ===See Also=== |