6.3.3 Do
loop
The do loop iterates
over a set of things, navigating from the current element. For example one could
query the relationships of an object like this:
do >relType
{/* Operations for relationships */ }Note that
do loops differ from
foreach.
Foreach will always look at the current
graph, and can only iterate over objects, roles or relationships directly
contained in that graph. Do and
dowhile will look at the current
element, and iterate over those instances of the specified type that are
attached to the current element in the current context. For this reason,
foreach will normally be the first loop
in a generator, and sub-loops will be
do or
dowhile, until you follow a link into a
new graph.
The dowhile
clause is a variant of do, differing
only in that it skips any trailing literal strings or
newlines on its last iteration over a
given set of elements. This is useful for avoiding trailing separators such as
commas or spaces after the last item to be output, e.g.
do .Process {id ', '} produces “1.0, 1.1, 1.2,”
dowhile .Process {id ', '} produces “1.0, 1.1, 1.2”Do
and dowhile can also with an argument
of a complex property, either a collection or a property pointing to an object
or other non-property. With a collection, the loop is executed once for each
item in the collection. With a property whose value is an object or other
non-property, the loop is executed once for that object; if there is no object
attached, the loop is not executed.
Special
do and
dowhile loops also exist for iterating
over lines of text properties, variables etc., over all properties of an
element, over decompositions and explosions, nested objects, the stack, and all
graphs: see below. Also, note that the loop filtering and ordering clauses
described below apply to
do and
dowhile loops in the same way as for
foreach
loops.