while, break

Syntax

while (condition) {
    body
}

where:

Description

The while statement processes the code between the braces while the condition evaluates to true.

You may leave the while loop using the break directive.

Examples

This code processes a UML element and its owners and calls a rule with each name as argument:

element : uml21.Element = ...;
while (element != null)
    @myRule(element.name);
    element = element.owner;
}

We could decide to break the loop when we encouter the name 'AccountPackage':

myPackage : uml21.Package = ...;
element : uml21.Element = ...;
while (element != null)
    // break if we encounter an 'AccountPackage' name
    if (element.name == "AccountPackage") {
        break;
    }

    @myRule(element.name);
    element = element.owner;
}