6.3.5 Iterating over lines of text properties, strings, variables and simple commands

The do and dowhile loops can also be used for iterating over the lines of a multi-line string: a property of data type Text, a MERL string, a MERL variable, or the output of a simple command like id.

For a Text property, the currently selected element should be the object, role, relationship of graph which has the text property, and the operator for the do loop should be the local name of the text property. The loop is then executed as many times as there are lines in that text property, including an empty last line if the text ends in a line break. Within the loop, id outputs the current line (with no line break character).
do :property
{ id }
This is particularly useful for translating line breaks in a property into character sequences which represent a new line or paragraph in a particular formatting language, such as RTF or HTML. The example below adds a <BR> tag in HTML; the newline is simply for clearer formatting of the HTML source.
do :Documentation
{ id '<BR>' newline }
It can also be used for programming languages where a comment is preceded by a certain character sequence, and is not allowed to extend over more than one line. The first example below shows how to make sure each line of a comment is preceded by the comment sequence, and the second example strings all the lines together into one long line, effectively replacing each carriage return with a space.
do :Documentation
{ '// ' id newline }

'// '
dowhile :Documentation
{ id ' ' }
The syntax for iterating over the lines of variables is similar:
do $myVar
{ id }
This can be useful in many situations, e.g. to execute a block multiple times with selected values, or to iterate over the lines of a text file read into a variable.

To iterate over literal strings, you can have the string spread over multiple lines:
do 'first
second
third'
{ id }
In all cases, you can add a translator as a suffix to the do loop argument, e.g. to translate some separator character into a newline:
to '%dotToNL
. \
' endto
do 'first.second.third'%dotToNL
{ id }
When iterating over the output of simple commands like id, using a translator is almost always necessary, as such outputs will generally only contain one line. The translator can split them into multiple lines by translating spaces to newlines etc.