🚀 Welcome to MDriven Learn –  Don’t miss the latest Release Notes.
OCLOperators foreach

Note: This is an Executable Action Language operator


The foreach operator iterates over a collection without transforming it. It is mainly used to perform side effects (such as delete, clear, assignments, or other actions) while returning the original collection unchanged.

Syntax

collection->foreach(item | expression)

Example

Delete all Orders for a Customer (Action)

self.Orders->foreach(o | o.delete)

Deletes every Order associated with the current Customer.

To iterate and return a list as the result, use collect.