[#while condition]
body
[/#while]
where:
The while directive processes the code between the start-tag and end-tag while the condition evaluates to true.
You may leave the while loop using the break directive.
This code prints the name of an element and of its owners:
Hierarchy:
[#set element : uml21.Element = ...]
[#while element != null]
${element.name}
[#set element = element.owner]
[/#while]
The above code would produce an output similar to the following:
Hierarchy:
Account
AccountPackage
Model
We could decide to break the loop when we encouter the name 'AccountPackage':
Hierarchy:
[#set element : uml21.Element = ...]
[#while element != null]
[#if element.name == "AccountPackage"]
[#break]
[/#if]
${element.name}
[#set element = element.owner]
[/#while]
Which would result to an output similar to the following:
Hierarchy:
Account
AccountPackage