Controlling the Flow Using Nested Loops

IEG provides the ability to create entities in the Datastore that are nested inside other entities. This section provides guidance on defining scripts to gather and display information in this area.

Scenario: It is required that several entities of the same type be registered in the Datastore. These entities may also contain entities themselves. For example, a number of Person entities need to be created to represent the members of a household. Each Person entity may also contain a number of Income entities representing the sources of income each household member has.

This information can be gathered in an IEG script using nested loops (a loop element containing another loop element). The information gathered can be displayed on a summary page using nested lists (a list element containing another list element).

The following should be considered when choosing the loop types to capture the required information:

If using nested loops it is then recommended to use one of the following 6 combinations:

Note that the use of While/For-each or For/For-each nested loops is not recommended. As a for-each loop relies on existing entities to iterate over, this would involve the outer loop in creating entities containing entities that already exist. This situation is not possible as it does not make sense.