"FOR" is the most important generator command. It is used to navigate through the hierarchical structure of input data.
Syntax
<for>variable iterator[@objname][<asc>sort expression][<desc>sort expression][<dist>]<where>{boolean_expression}[<set>set environment variable<div>divider<wrap>wrap[<@>container]<begin>body<endfor>
for each element in iterator collection of objname object matching filter expression generates code based on body expression

- variable - name (or sequence of names connected by ".") of variable(s) used to denote current element
- iterator - name (or sequence of names connected by ".") of collection. Optionally iterator can be followed by objname identifier. Objname is used to change the object iterator should be applied to. Note: objname doesn't change the container; to change it use environment element. Depends on {objname} object type can be the following (type with minus sign on the end means "do not proceed inherited attributes/associations")

- packages; applicable to packages, iterates through child packages
- classes; applicable to packages, iterates through child classes
- attributes, attributes-; applicable to classes, iterates through class attributes
- methods; applicable to classes, iterates through class methods
- parameters; applicable to methods, iterates through method parameters
- roles (associations), roles- (associations-); applicable to classes, iterates through roles associated with given class
- selfroles (associations1), selfroles- (associations1-); applicable to classes, iterates through opposite roles associated with given class
- type; applicable to roles, returns the opposite class
- refattribute; applicable to roles, returns pseudo attribute associated with role
- parent; applicable to packages, returns the parent package

- objname - optional, name of object - owner of collection, by default it is current object
- boolean expression - is used to filter out elements meet your requirements. See IF command
- set environment variable - is used to set environment variable for each iteration step
- divider - expression inserted between generated codes of different elements
- wrap - expression iserted in the middle of the generated code if length of the line exeeds 100 characters
- container - identifies container
- body - expression generated for each element of collection matching the boolean expression

Example of usage
To show list of classes in a UML package use the following code
<for>x classes<begin>Class %x.name%
<endfor>
Hierarchical browsing
Hierarchical browsing is the core idea of MGL generation. Each hierarchical structure can be passed by sequence of encloded iterators. I.e. if we want to generate list of methods for all classes in the package we start with iteration through list of package classes; for each class we print class name and iterate throug list of class methods; for each method we print method name and iterate through list of parameters; for each parameter we print parameter name and data type. The assumption is that generated source code can be represented as hierarchical structure resembling structure of the UML class model.
Here is whole hierarchy of UML elements supported by NewGen

- root package

- sub packages
- classes

- class attributes
- class methods

- method parameters

- associations with another classes (assiciation roles)

- singular iterator for opposite class

Note, that hierarchy can have endless circular connections through class-association-class link. Generator has limit of maximum iteration deepness. By default it is 20 levels deep.
Iteration is executed with <FOR> command. The above example can be coded as
<for>c classes<begin>
class name = %c.name%
<for>m methods<begin>
method name = %.m.name%
<for>p params<begin>
parameter = %p.name% of %p.type% type
<endfor>
<endfor>
<endfor>