Unfortunately it cannot be done. The loop operator has a guard
condition and a number of iterations between minint
and maxint
. I think, this doesn't allow "for each loop" semantics. If you want to add this, it must be done with a user defined stereotype «for each loop»
:
An example usage is:
Please note that the note symbol is a not a comment
, but the notation for the stereotype properties. They reference the property e
of Client1
and i
of the Interaction Example1
(see diagram below). The i-Property is represented by a Lifeline and will refer to a different object in each occurrence of the loop content. This is achieved here by the user defined semantics of my «for each loop»
.
As an alternative you could add a semantic free comment
with the same content. Misusing the guard
for this purpose is not recommended.
If you want to use a java like iterator the diagram could look like this:
This diagram also shows, how to refer to different objects over time: The return value of a reply
message is assigned to a Property
of the Interaction or of the Class represented by the Lifeline or a Parameter
.