"For each" iterator usage specifics

1C:Enterprise features a universal method for iterating collections: the "For each" iterator. You can use it for iterating most of the collections. The iterator allows recording all collection elements to a specified variable, one by one.

For some collections, you can get collection elements by their numeric indexes. You can iterate such collections both by using iterators and by using indexes. An example of such a collection is Array.

However, for some collections, you cannot get collection elements by indexes because the elements are not ordered. In such cases the "For each" iterator helps iterate the collection. Note that the iteration order should not be interpreted as the order of collection elements. When you use the "For each" iterator on an unordered collection, the resulting iteration order is generally unpredictable. Therefore, building your collection processing algorithms based on iteration order is not allowed. An example of such a collection is Map.

It is important to remember that the iteration order might change unpredictably after adding or removing collection elements. This behavior can vary between collections. Therefore, it is recommended that you do not add or remove collection elements while "For each" iterating is being performed. If you need to add or remove elements, we recommend that you use indexes, or mark elements to delete them later, after the iterating is complete.

Next page: 1C:Enterprise script execution process

Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.