KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Consider using For Each for Collections and Entity Selections
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: August 10, 2020

If you are still iterating over your collections or entity selections using the For command like this:

For($i;0;$collection.length-1)
// do stuff with collection
End For


You should really consider using For Each instead!

The For Each command will simpify your code while performing the following tasks:

Looping over a collection:
For Each($element;$collection)
// do stuff with each $element of the $collection
End For Each


Looping over every property of an $object
For Each($propertyNamel;$object)
// do stuff with each $property
// $value := $object[$propertyName]
End For Each


Looping over an Entity Selection:
For Each($entity;$entitySelection)
// do stuff with each $entity of the $entitySelection
End For Each