Chapter 12: Using for Loops to Iterate Through Elements

Use for loops to iterate through lists of medini analyze elements, such as child elements in SysML or requirements models, to generate list entries, table rows, or entire document sections.

A for loop begins with {m:for x|elementname} and ends with {m:endfor}. The variable x contains the current element of the iteration.

In the following example, the term req is used as the variable as M2Doc loops through the list of elements. The result is a numbered list of the requirement names in the model myRequirementsModel.

Example

{m:for req | myRequirementsModel.requirements}
    1. {m:req.name}
{m:endfor}

Note:  To use a for loop to populate a table, see About Tables.